[ColorModeProvider] Color mode does not work in production
See original GitHub issueDescribe the bug Switching between dark and light mode is not working in production build.
Expected Behavior After clicking on the color mode switcher button it should be switching theme colors between light and dark.
To Reproduce
I am using chakra-ui with gatsby with below mentioned versions:
"gatsby": "^2.18.8", "gatsby-plugin-chakra-ui": "^0.1.0",
code
<ThemeProvider theme={theme}> <CSSReset /> <ColorModeProvider> <Header siteTitle={data.site.siteMetadata.title} /> <main>{children}</main> <Footer /> </ColorModeProvider> </ThemeProvider>
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (8 by maintainers)
Top Results From Across the Web
Gatsby w/ Chakra UI ColorMode not working - Stack Overflow
I'm using Gatsby w/ Chakra UI and have an issue with either local storage or how the ColorMode is being accessed.
Read more >Color Mode - Chakra UI
Color Mode. Chakra UI comes with built-in support for managing color mode in your apps. By default, most of Chakra's components are dark...
Read more >Advanced techniques in Chakra UI - LogRocket Blog
colorMode is the current color mode, and toggleColorMode is the function to toggle the color mode. We pass the toggleColorMode function to the ......
Read more >Upgrading to v1 - Chakra UI
ColorModeProvider : Provides color mode (light or dark) context to all components. ... You can skip this if you are not already using...
Read more >Designing and implementing dark mode on a website
Dark mode or light-on-dark color scheme is a new popular trend in user interface ... Adding the third auto option solves this problem....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @amolmt & @MykalMachon! I’ve got it working successfully working for Gatsby. The trick is that the root of Gatsby is
gatsby-browser.js
. So the code I’ve got is:If you need further reference, my personal portfolio repo is public, here.
Hello @amolmt, I think this is more an issue with Gatsby (specifically, React) than it is with Chakra-UI.
I’ve experienced bugs similar to this one myself when using gatsby. From what I know it has to do with the way Gatsby implements React’s rehydrate method on statically generated pages. You can read more about it here and here.