use-tweaks
use-tweaks copied to clipboard
fix: useEffect when SSR
When SSR, useLayoutEffect prints a warning. This PR fixes this by swapping the hook with a useEffect if we are on the server. This is a common way to solve this problem:
- https://github.com/streamich/react-use/blob/6737092ad9260ca1fe481bf4c10ffa650ae35476/src/useIsomorphicLayoutEffect.ts
- https://github.com/mui-org/material-ui/blob/e53a9543cf28b67be6216e5f0ffd99be553cb258/packages/material-ui-utils/src/useEnhancedEffect.js

+1 on this, makes a lot of noise in the log when developing with Next.js
@mysterybear can you test the PR and give feedback? I'll merge then 👍
Hi @gsimone thanks for quick reply, I've tested using JS and it seems to work fine here: https://codesandbox.io/s/github/mysterybear/tweaks-next-ssr-use-effect-test?file=/pages/index.js
I just took the example codesandbox code and pasted it into a Next.js project and pointed use-tweaks at the patch author's branch, hope that's okay
Edit: wanted to try with TS too, but getting the same problem as #43 even with v0.3.1
Any chance this gets ever merged ?
Hey @enzoferey (and @mysterybear), we pretty much moved all efforts to https://github.com/pmndrs/leva; if you want to help with use-tweaks, let me know and I can make you maintainer 👍