Is it OK to call setState from within shouldComponentUpdate?

前端 未结 2 2008
眼角桃花
眼角桃花 2021-02-07 13:35

In response to a state change, I want to trigger another state change. Is that inherently a bad idea?

The specific sort of scenario is that the component is modeled as a

2条回答
  •  青春惊慌失措
    2021-02-07 13:58

    No. Please use componentWillReceiveProps instead. It has the same signature of shouldComponentUpdate and you're safe to call this.setState there.

提交回复
热议问题