IssueRaiser

Calling setState in componentDidUpdate

It might be worth revisiting [react/no-did-update-set-state](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md). Now that `componentWillReceiveProps()` is being deprecated, `componentDidUpdate()` is the only "safe" way to detect changes in props and set state accordingly. The [React docs](https://reactjs.org/docs/react-component.html#componentdidupdate) say calling `setState()` in `componentDidUpdate()` is permitted, albeit with caveats. > You may call setState() immediately in componentDidUpdate() but note that it must be wrapped in a condition like in the example above, or you’ll cause an infinite loop. It would also cause an extra re-rendering which, while not visible to the user, can affect the component performance.

Posted by dlwalsh on Jul 30, 2018, 5:54 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Software)

Calling setState in componentDidUpdate

dlwalshJul 30, 2018, 5:54 AM

It might be worth revisiting [react/no-did-update-set-state](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md). Now that `componentWillReceiveProps()` is being deprecated, `componentDidUpdate()` is the only "safe" way to detect changes in props and set state accordingly. The [React docs](https://reactjs.org/docs/react-component.html#componentdidupdate) say calling `setState()` in `componentDidUpdate()` is permitted, albeit with caveats. > You may call setState() immediately in componentDidUpdate() but note that it must be wrapped in a condition like in the example above, or you’ll cause an infinite loop. It would also cause an extra re-rendering which, while not visible to the user, can affect the component performance.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue