-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hydrate component changes state while rendering, causing a react warning #3611
Comments
mmm I'm not able to run Wagmi yet, but yep It shouldn't be called in a useEffect because the idea is to hydrate the store during page load, but should be called once possible fix might be const active = useRef(true)
// Hydrate for non-SSR
if (!config._internal.ssr && active.current){
onMount()
active.current = false
} |
Thanks. FWIW, when I triggered it, it was because I mistakenly had some state above the |
This issue has been locked since it has been closed for more than 14 days. If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion. |
Describe the bug
The Hydrate component performs state mutations while rendering, which react detects and logs the https://reactjs.org/link/setstate-in-render warning/error.
Seems to originate here: https://github.com/wevm/wagmi/blob/main/packages/react/src/hydrate.ts#L21
For some reason Hydrate calls
onMount()
inside a useEffect in the server side, but not in a useEffect on the client side. I've not read through the code to understand why, but presumably this error wouldn't occur if the call was made from a useEffect.Link to Minimal Reproducible Example
https://stackblitz.com/edit/new-wagmi-judl71
Steps To Reproduce
The Change Root State button here is triggering a render of the component that hosts Wagmi's context, which causes Hydrate to re-render and perform its state-change.
Wagmi Version
2.5.7
Viem Version
2.7.10
TypeScript Version
5.3.3
Check existing issues
Anything else?
Can work around by hoisting the Wami context above any other contexts to prevent it re-rendering.
The text was updated successfully, but these errors were encountered: