Skip to content

Instantly share code, notes, and snippets.

@haldarmahesh
Created October 19, 2018 06:34
Show Gist options
  • Save haldarmahesh/9a794416aae77e8416aa2037b913db2f to your computer and use it in GitHub Desktop.
Save haldarmahesh/9a794416aae77e8416aa2037b913db2f to your computer and use it in GitHub Desktop.
react lifecycle 16.4 blog
static getDerivedStateFromProps(props, state) {
if (state.value !== props.value) {
return {
derivedValue: deriveValueFromProps(props),
mirroredProp: props.value
}
}
// when null is returned no update is made to the state
return null;
}
// after getDerivedStateFromProps the state looks like as follows:
// {
// derivedValue: someValue,
// mirrordValue: newPropValue
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment