Skip to content
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

Investigate useLayoutEffect console error #37

Closed
2 tasks
taysea opened this issue Aug 1, 2023 · 2 comments · Fixed by #41
Closed
2 tasks

Investigate useLayoutEffect console error #37

taysea opened this issue Aug 1, 2023 · 2 comments · Fixed by #41
Assignees

Comments

@taysea
Copy link
Collaborator

taysea commented Aug 1, 2023

Currently, a console error is thrown about useLayoutEffect:

Screen Shot 2023-08-01 at 3 38 38 PM

To do:

  • Investigate cause (likely use of ReactDOMServer + useLayoutEffect from grommet component does't place nicely because useLayoutEffect is client-side only)
  • Determine best approach to stop error from appearing in console. File PR to fix.
@taysea
Copy link
Collaborator Author

taysea commented Aug 2, 2023

Mike mentioned we have a strategy of how to deal with this in Grommet, so reach out to him for where to look.

@MikeKingdom
Copy link

From grommet's use-isomorphic-layout-effect.js:

/* eslint-disable no-restricted-imports */
import { useLayoutEffect as vanillaUseLayoutEffect, useEffect } from 'react';

/**
 * A substitute for React's useLayoutEffect, which does not generate warnings on
 * SSR. It is named useLayoutEffect so that all eslint rules applying to the
 * original useLayoutEffect would also apply to it.
 * This solution was suggested by Alex Reardon.
 * @see https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
 * @see https://github.com/grommet/grommet/issues/4765
 */
export const useLayoutEffect =
  typeof window !== 'undefined' ? vanillaUseLayoutEffect : useEffect;

export default useLayoutEffect;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants