componentWillReceiveProps not firing

前端 未结 4 2163
醉梦人生
醉梦人生 2021-02-18 12:51

In my other classes, componentWillReceiveProps was working nicely, but for some reason, it isn\'t firing here.

ItemView.jsx

class ItemView extends React.         


        
4条回答
  •  灰色年华
    2021-02-18 13:30

    If anyone else is having a problem with this...

    componentWillReceiveProps will not be called if you are receiving the exact same props as before. What you can do to get around it is add a dummy prop that iterates every time you want to send the same prop to the component in case that component internally resets itself somehow

    click() {
        this.setState({counter: ++this.state.counter, unchangingProp:true})
    }
    
    

    This way componentWillRecieveProps will be triggered every time.

提交回复
热议问题