Is it a good practice to modify a component's state and then call “setState(this.state)”?

后端 未结 3 972
不思量自难忘°
不思量自难忘° 2021-01-22 06:52

I\'m using ReactJS.

I have a statefull component (stopwatch container) and multiple child components which are stateless (stopwatches).

In the outer component,

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-22 07:07

    Instead of calling this.setState(this.state) you can just call this.forceUpdate().

    Just remember that this is not recommended way of updating components state. If you are unsure about your modifications take a look on Immutability Helpers.

提交回复
热议问题