Next.js Discord

Discord Forum

undefined theme next-themes useTheme()

Answered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
Please have a look at this project
https://stackblitz.com/edit/stackblitz-starters-l2ed2d?file=src%2Fapp%2Fcomponents%2FThemeToggleIcon.tsx

I'm getting undefined theme for some reason. I think it has to do with hydration but I've already added the necessary pages to client side also have used useEffect to render the component first. Have tried adding use client to every page (just in case if it works lol) but that didn't work either.

Any help will be appreciated. Thank you!!

5 Replies

Answer
Asiatic LionOP
Ohh yeah, didn't wrap the Navbar component inside the ThemeProvider.
Ahhhh
Was new to ThemeProvider so I assume that from wherever the theme us switching we have to wrap that inside ThemeProvider
Because body is not inside theme provider but it's theme is changing when I toggle