Browse Source

Update getDerivedStateFromProps docs

main
Andrew Clark 7 years ago
parent
commit
983476e3f3
  1. 4
      content/docs/reference-react-component.md

4
content/docs/reference-react-component.md

@ -189,9 +189,9 @@ If you "fork" props by using them for state, you might also want to implement [`
static getDerivedStateFromProps(nextProps, prevState)
```
`getDerivedStateFromProps` is invoked after a component is instantiated as well as when it receives new props. It should return an object to update state, or null to indicate that the new props do not require any state updates.
`getDerivedStateFromProps` is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.
Note that if a parent component causes your component to re-render, this method will be called even if props have not changed. You may want to compare new and previous values if you only want to handle changes.
Note that this method is fired on *every* render, regardless of the cause. This is in contrast to `UNSAFE_componentWillReceiveProps`, which only fires when the parent causes a re-render and not as a result of a local `setState`.
* * *

Loading…
Cancel
Save