Skip to content

Component life-cycle methods for update  #2073

@syranide

Description

@syranide
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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions