How to use shouldComponentUpdate with React Hooks?

后端 未结 2 977
孤街浪徒
孤街浪徒 2020-12-14 15:11

I\'ve been reading these links:
https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-shouldcomponentupdate
https://reactjs.org/blog/2018/10/23/react-v-16-6.htm

相关标签:
2条回答
  • 2020-12-14 16:01

    Also you can use in export statement like:

    export default memo(Modal, (prevState, nextState) => prevState.show === nextState.show) ;
    
    0 讨论(0)
  • 2020-12-14 16:05

    Here is the documentation for React.memo

    You can pass a function to control the comparison :

    const Modal = React.memo(
      props => {...},
      (prevProps, nextProps) => prevProps.show === nextProps.show
    );
    

    when the function returns true, the component will not be re-rendered

    0 讨论(0)
提交回复
热议问题