rsnext/errors/multiple-flush-effects.md
Gerald Monaco 944c734d04
Add unstable_useFlushEffects hook (#34117)
Implements https://github.com/vercel/next.js/issues/30997 with some minor tweaks to the design:

* The hook is moved to Client Components (e.g. `pages/_app` instead of `pages/_document`). This was a silly oversight in the original design: the hook needs to be called during server prerendering.

* `useFlushEffects` instead of `useFlushEffect` as there isn't a particularly safe way to implement the singular semantics as a Client Component hook given the current implementation of server rendering.

---

Fixes #30997
2022-02-18 00:18:28 +00:00

410 B

The useFlushEffects hook cannot be used more than once.

Why This Error Occurred

The useFlushEffects hook is being used more than once while a page is being rendered.

Possible Ways to Fix It

The useFlushEffects hook should only be called inside the body of the pages/_app component, before returning any <Suspense> boundaries. Restructure your application to prevent extraneous calls.