我正在将NextJs与Framer Motion一起使用。一切正常,但是我得到了这个警告:
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client.
答案 0 :(得分:0)
Next进行SSR,这就是为什么它在useLayoutEffect时抛出此警告而不在服务器上运行的原因。
签名与useEffect相同,但是在所有DOM突变后都会同步触发。使用它从DOM读取布局并同步重新渲染。在浏览器有机会绘制之前,useLayoutEffect中安排的更新将被同步刷新。