React.js - componentWillReceiveProps being hit twice

前端 未结 1 788
故里飘歌
故里飘歌 2021-01-02 00:48

I have a React.js component that\'s being rendered like so:

    ;

There are some events on the pag

相关标签:
1条回答
  • 2021-01-02 01:08

    Your Social component is probably being rendered twice because setState is called twice on the parent component. It may be setting properties other than email but your render function is called so the Social component renders twice.

    You can implement shouldComponentUpdate method in the Social component to prevent second rendering:

    shouldComponentUpdate: function(nextProps, nextState) {
        return nextProps.email != this.props.email;
    }
    
    0 讨论(0)
提交回复
热议问题