I am having a weird issue on the static file after run gatsby build.
DOM's attributes (like className) could not be updated by listening to the prop change, but not the case of DOM's content, like text or DOM's children.
- Only happening after gatsby-build, aka in SSR
// Verison 1, not working
const ThemeProvider = ({ isLight, children }) => {
return (
<div className={isLight ? 'light-theme' : 'dark-theme'}> // <- does not change when `isLight` updating
<h1>{isLight ? 'light-theme' : 'dark-theme'}</h1> // <- changes when `isLight` updating
{children}
</div>
)
}
// Verison 2, not working
// still having the same issue
const ThemeProvider = ({ isLight, children }) => {
if (isLight)
return (
<div className="light-theme">
<h1>{isLight ? 'light-theme' : 'dark-theme'}</h1>
{children}
</div>
)
return (
<div className="dark-theme">
<h1>{isLight ? 'light-theme' : 'dark-theme'}</h1>
{children}
</div>
)
}
// Verison 3, working
const ThemeProvider = ({ isLight, children }) => {
if (isLight)
return (
<div className="light-theme">
<h1>{isLight ? 'light-theme' : 'dark-theme'}</h1>
{children}
</div>
)
return (
<section className="dark-theme"> // <-- change to the different DOM, everything works fine
<h1>{isLight ? 'light-theme' : 'dark-theme'}</h1>
{children}
</section>
)
}