mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Explain how StrictMode affects function components and hooks (#2515)
* Update strict-mode.md * Fix links * docs: specify which kind of function component * Update content/docs/strict-mode.md * Update strict-mode.md Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c2eb543b52
commit
9e5a358cb2
@@ -97,13 +97,13 @@ Render phase lifecycles include the following class component methods:
|
||||
|
||||
Because the above methods might be called more than once, it's important that they do not contain side-effects. Ignoring this rule can lead to a variety of problems, including memory leaks and invalid application state. Unfortunately, it can be difficult to detect these problems as they can often be [non-deterministic](https://en.wikipedia.org/wiki/Deterministic_algorithm).
|
||||
|
||||
Strict mode can't automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following methods:
|
||||
Strict mode can't automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following functions:
|
||||
|
||||
* Class component `constructor` method
|
||||
* The `render` method
|
||||
* `setState` updater functions (the first argument)
|
||||
* The static `getDerivedStateFromProps` lifecycle
|
||||
* The `shouldComponentUpdate` method
|
||||
* Class component `constructor`, `render`, and `shouldComponent` methods
|
||||
* Class component static `getDerivedStateFromProps` method
|
||||
* Function component bodies
|
||||
* State updater functions (the first argument to `setState`)
|
||||
* Functions passed to `useState`, `useMemo`, or `useReducer`
|
||||
|
||||
> Note:
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user