Conditionally Rendering Elements and Classes without Hydration Error #51
Unanswered
penguyen72
asked this question in
Q&A
Replies: 1 comment
-
Hi @penguyen72 !
Not ideal, because this component will rerender twice. Another approach might be to render both icons and use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I want to use
theme
to conditionally render an icon. I am trying to add a toggle button to switch between dark mode and light mode. It seems like doingtheme === 'dark' ? <SunIcon /> : <MoonIcon />
causes hydration issues. Since theme is null on the server<MoonIcon />
will be set on the server and hydrated with<SunIcon />
if the user has dark mode set. How would I resolve this?Beta Was this translation helpful? Give feedback.
All reactions