react函数式组件怎么根据state来决定是否重新render

类组件能通过shouldComponentUpdate来根据props和state决定是否render,函数式组件能通过React.memo来根据props决定render,但是怎么根据state来决定重新render呢,好像没看到hooks api有没有相关的

阅读 4.9k
2 个回答

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...

函数式组件何来的 state 呢?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题