Skip to content

Commit

Permalink
Update use-component-will-receive-update.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works authored Oct 10, 2024
1 parent a3e7931 commit e1f8874
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/pages/use-component-will-receive-update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ If you need to edit other components' states, write it like this:

```js
useComponentWillReceiveUpdate(() => {
// Force React to immediately flush scheduled/batched updates
flushSync(() => setLocalState(false))
// By the time flushSync finishes and reaches this line, the DOM update
// for local state change has finished, you can now safely trigger parent
// components' re-render.
props.setParentState(false)
}, [state])
```

0 comments on commit e1f8874

Please sign in to comment.