mithi / epic-react-exercises

Practical React exercises with detailed solutions.
https://epic-react-exercises.vercel.app
Apache License 2.0
161 stars 39 forks source link

🐞🐞 Investigate useLayoutEffect warnings by next js #16

Closed mithi closed 3 years ago

mithi commented 3 years ago
Screen Shot 2020-12-22 at 8 22 42 AM

https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85

// ***************
// IMPORTANT: Use isomorphic effect
// ***************
// React currently throws a warning when using useLayoutEffect on the server.
// To get around it, we can conditionally useEffect on the server (no-op) and
// useLayoutEffect in the browser. We need useLayoutEffect because we want
// `connect` to perform sync updates to a ref to save the latest props after
// a render is actually committed to the DOM.