We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
问题描述
使用useState的更新函数去更新值,拿到最新的值之后,操作然后返回这个值,结果发现不更新,值是个二维数组,操作是删除其中的某一个数据
问题解决
官方文档里写了一段话React 使用 Object.is 比较算法 来比较 state, 这意味着useState是通过判断比较前后值是否是同一个对象来决定是否更新,而如果只是个二位数组或者对象,直接在原数据上操作,并且返回原数据,则比较的是同一个对象,当然就不更新了,所以react提倡state使用immutable数据
React 使用 Object.is 比较算法 来比较 state
参考资料
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题描述
问题解决
参考资料
The text was updated successfully, but these errors were encountered: