-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Closed
Description
getInitialState
componentWillMount (setState is applied without side-effects)
componentDidMount (setState causes an update)
All good, everything makes sense for mounting.
componentWillReceiveProps (setState is applied without side-effects)
shouldComponentUpdate
componentWillUpdate (setState is disallowed)
componentDidUpdate (setState causes an update)
If you need to update state and it isn't based on the new props, there is no place to do it it seems. Sure, you can stick it in componentWillReceiveProps, but that puts it before shouldComponentUpdate which is bad. componentWillUpdate seems like the obvious choice but it's not allowed, is there a good reason for this or is it "because you shouldn't"?
Personally, I don't think there are very many reasons to call setState from componentWillUpdate, but I have encountered a scenario or two where I would like to call setState after shouldComponentUpdate (i.e. in componentWIllUpdate).
Metadata
Metadata
Assignees
Labels
No labels