Skip to content

Conversation

@aolongyu
Copy link

No description provided.

export default () => {
const [list, setList] = useState([]);
// list需要定义是什么类型的,这里给定Array
const [list, setList] = useState(Array);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型不是这么写的
useState()

console.log(data);
console.log(list);
setList(list);
// 解构(list是引用类型,改变其中的值不会导致重新渲染(因为地址值不会改变),这里的myList不属于引用类型)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

假象,明天的考核中会有体现。

{
list.map(item => <p>{item.state}</p>)
// 增加key值
list.map((item, index) => <p key={index}>{item.state}</p>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用index作为key。
自己查一查 react 中的 key 有什么作用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants