mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-25 23:05:23 +00:00
Link to newer blog post from the older one (#981)
* Link to newer blog post from the older one * Update 2018-03-27-update-on-async-rendering.md * Update 2018-03-27-update-on-async-rendering.md
This commit is contained in:
@@ -39,10 +39,14 @@ Before we begin, here's a quick overview of the lifecycle changes planned for ve
|
||||
|
||||
`embed:update-on-async-rendering/definition-getderivedstatefromprops.js`
|
||||
|
||||
The new static `getDerivedStateFromProps` lifecycle is invoked after a component is instantiated as well as when it receives new props. It can return an object to update `state`, or `null` to indicate that the new `props` do not require any `state` updates.
|
||||
The new static `getDerivedStateFromProps` lifecycle is invoked after a component is instantiated as well as before it is re-rendered. It can return an object to update `state`, or `null` to indicate that the new `props` do not require any `state` updates.
|
||||
|
||||
Together with `componentDidUpdate`, this new lifecycle should cover all use cases for the legacy `componentWillReceiveProps`.
|
||||
|
||||
>Note:
|
||||
>
|
||||
>Both the older `componentWillReceiveProps` and the new `getDerivedStateFromProps` methods add significant complexity to components. This often leads to [bugs](/blog/2018/06/07/you-probably-dont-need-derived-state.html#common-bugs-when-using-derived-state). Consider **[simpler alternatives to derived state](/blog/2018/06/07/you-probably-dont-need-derived-state.html)** to make components predictable and maintainable.
|
||||
|
||||
### New lifecycle: `getSnapshotBeforeUpdate`
|
||||
|
||||
`embed:update-on-async-rendering/definition-getsnapshotbeforeupdate.js`
|
||||
@@ -121,6 +125,10 @@ Rather than passing a subscribable `dataSource` prop as we did in the example ab
|
||||
|
||||
### Updating `state` based on `props`
|
||||
|
||||
>Note:
|
||||
>
|
||||
>Both the older `componentWillReceiveProps` and the new `getDerivedStateFromProps` methods add significant complexity to components. This often leads to [bugs](/blog/2018/06/07/you-probably-dont-need-derived-state.html#common-bugs-when-using-derived-state). Consider **[simpler alternatives to derived state](/blog/2018/06/07/you-probably-dont-need-derived-state.html)** to make components predictable and maintainable.
|
||||
|
||||
Here is an example of a component that uses the legacy `componentWillReceiveProps` lifecycle to update `state` based on new `props` values:
|
||||
`embed:update-on-async-rendering/updating-state-from-props-before.js`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user