类组件能通过shouldComponentUpdate
来根据props和state决定是否render,函数式组件能通过React.memo
来根据props决定render,但是怎么根据state来决定重新render呢,好像没看到hooks api有没有相关的
类组件能通过shouldComponentUpdate
来根据props和state决定是否render,函数式组件能通过React.memo
来根据props决定render,但是怎么根据state来决定重新render呢,好像没看到hooks api有没有相关的
4 回答1.7k 阅读
2 回答1.1k 阅读✓ 已解决
2 回答2.6k 阅读
1 回答972 阅读✓ 已解决
1 回答698 阅读✓ 已解决
2 回答861 阅读✓ 已解决
2 回答1k 阅读
React.memo doesn’t compare state because there is no single state object to compare. But you can make children pure too, or even optimize individual children with useMemo.
参考: https://reactjs.org/docs/hook...