Update getDerivedStateFromProps docs

This commit is contained in:
Andrew Clark
2018-05-23 15:31:27 -07:00
parent 1dfdfd8595
commit 983476e3f3

View File

@@ -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`.
* * *