Skip to content

Commit 9e8bfd6

Browse files
author
Brian Vaughn
committed
Moved UNSAFE_ renaming notes higher up to be more easily noticed
1 parent cfc6d90 commit 9e8bfd6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

content/docs/reference-react-component.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,16 @@ The lifecycle methods below are marked as "legacy". They still work, but we don'
430430
UNSAFE_componentWillMount()
431431
```
432432

433+
> Note
434+
>
435+
> This lifecycle was previously named `componentWillMount`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
436+
433437
`UNSAFE_componentWillMount()` is invoked just before mounting occurs. It is called before `render()`, therefore calling `setState()` synchronously in this method will not trigger an extra rendering. Generally, we recommend using the `constructor()` instead for initializing state.
434438

435439
Avoid introducing any side-effects or subscriptions in this method. For those use cases, use `componentDidMount()` instead.
436440

437441
This is the only lifecycle method called on server rendering.
438442

439-
> Note
440-
>
441-
> This lifecycle was previously named `componentWillMount`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
442-
443443
* * *
444444

445445
### `UNSAFE_componentWillReceiveProps()`
@@ -448,9 +448,13 @@ This is the only lifecycle method called on server rendering.
448448
UNSAFE_componentWillReceiveProps(nextProps)
449449
```
450450

451+
> Note
452+
>
453+
> This lifecycle was previously named `componentWillReceiveProps`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
454+
451455
> Note:
452456
>
453-
> We added "UNSAFE_" to this lifecycle's name because using it often leads to bugs and inconsistencies.
457+
> Using this lifecycle method often leads to bugs and inconsistencies
454458
>
455459
> * If you need to **perform a side effect** (for example, data fetching or an animation) in response to a change in props, use [`componentDidUpdate`](#componentdidupdate) lifecycle instead.
456460
> * If you used `componentWillReceiveProps` for **re-computing some data only when a prop changes**, [use a memoization helper instead](/blog/2018/06/07/you-probably-dont-need-derived-state.html#what-about-memoization).
@@ -464,10 +468,6 @@ Note that if a parent component causes your component to re-render, this method
464468

465469
React doesn't call `UNSAFE_componentWillReceiveProps()` with initial props during [mounting](#mounting). It only calls this method if some of component's props may update. Calling `this.setState()` generally doesn't trigger `UNSAFE_componentWillReceiveProps()`.
466470

467-
> Note
468-
>
469-
> This lifecycle was previously named `componentWillReceiveProps`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
470-
471471
* * *
472472

473473
### `UNSAFE_componentWillUpdate()`
@@ -476,16 +476,16 @@ React doesn't call `UNSAFE_componentWillReceiveProps()` with initial props durin
476476
UNSAFE_componentWillUpdate(nextProps, nextState)
477477
```
478478

479+
> Note
480+
>
481+
> This lifecycle was previously named `componentWillUpdate`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
482+
479483
`UNSAFE_componentWillUpdate()` is invoked just before rendering when new props or state are being received. Use this as an opportunity to perform preparation before an update occurs. This method is not called for the initial render.
480484

481485
Note that you cannot call `this.setState()` here; nor should you do anything else (e.g. dispatch a Redux action) that would trigger an update to a React component before `UNSAFE_componentWillUpdate()` returns.
482486

483487
Typically, this method can be replaced by `componentDidUpdate()`. If you were reading from the DOM in this method (e.g. to save a scroll position), you can move that logic to `getSnapshotBeforeUpdate()`.
484488

485-
> Note
486-
>
487-
> This lifecycle was previously named `componentWillUpdate`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
488-
489489
> Note
490490
>
491491
> `UNSAFE_componentWillUpdate()` will not be invoked if [`shouldComponentUpdate()`](#shouldcomponentupdate) returns false.

0 commit comments

Comments
 (0)