You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
componentWillMount() is invoked immediately before mounting occurs. It is called before render(), therefore setting state in this method will not trigger a re-rendering. Avoid introducing any side-effects or subscriptions in this method.
The text was updated successfully, but these errors were encountered:
@adidahiya Related to state, every component which has state, should override componentWillReceiveProps. Otherwise, component will work on old state, which would have initialized based on initial props. So is it possible to add a rule to detect that and warn? (should I create a new issue for this?)
@brsanthu yeah, that should be filed as a separate issue.
It sounds like you're referring to this pattern?
constructor(props){// initialize based on initial propsthis.state={ ... };}
This seems to be the only situation where a missing componentWillRecieveProps implementation is likely wrong. Otherwise, you can happily use stateful components without implementing this lifecycle method.
AWare
added a commit
to guardian/dotcom-rendering
that referenced
this issue
Sep 7, 2018
There are a couple places I'd like to ban
this.setState
in component lifecycle methods:1. in
componentWillUpdate
Doing this can lead to infinite recursion.
2. in
componentDidUpdate
Same as eslint rule https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
3. in
componentWillMount
componentWillMount() is invoked immediately before mounting occurs. It is called before render(), therefore setting state in this method will not trigger a re-rendering. Avoid introducing any side-effects or subscriptions in this method.
The text was updated successfully, but these errors were encountered: