Skip to content

Commit

Permalink
Update docs/src/pages/use-component-will-receive-update.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Oct 11, 2024
1 parent eccd2a1 commit 7c4220f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions docs/src/pages/use-component-will-receive-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ This hook is a helper for the above pattern.
useComponentWillReceiveUpdate(() => setState(false), [state])
```

This only applies to states of the current component.
Modifying states from other components causes React reporting errors.
You may also want to read [(Avoid) Notifying parent components about state changes](https://react.dev/learn/you-might-not-need-an-effect#notifying-parent-components-about-state-changes) and [(Avoid) Passing data to the parent](https://react.dev/learn/you-might-not-need-an-effect#passing-data-to-the-parent).
If you need to edit other components' states, write it like this:
This should only apply to states of the current component. Modifying states of other components causes React reporting errors. You may also want to read [(Avoid) Notifying parent components about state changes](https://react.dev/learn/you-might-not-need-an-effect#notifying-parent-components-about-state-changes) and [(Avoid) Passing data to the parent](https://react.dev/learn/you-might-not-need-an-effect#passing-data-to-the-parent).

If you really need to directly modify other components' states (E.g. when working with third-party libraries/components/SDKs where you don't have control of that code), use `flushSync` to separate two state updates:

```js
import { flushSync } from 'react-dom'
Expand Down

0 comments on commit 7c4220f

Please sign in to comment.