Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created May 22, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleshevlin/4ee9e57cfb0b509627e8087fc4abc0bd to your computer and use it in GitHub Desktop.
Save kyleshevlin/4ee9e57cfb0b509627e8087fc4abc0bd to your computer and use it in GitHub Desktop.
function Script() {
return (
<script
dangerouslySetInnerHTML={{ __html: `(${setCSSVars.toString()})()` }}
/>
)
}
function setCSSVars() {
const theme = localStorage.getItem('kyleshevlin:theme') || 'light'
const themes = {
light: ['--color-background="#fff"'],
dark: ['--color-background="#000"'],
}
const html = document.documentElement
html.setAttribute('style', themes[theme].join(';'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment