Skip to content

Instantly share code, notes, and snippets.

@chetanraj
Created August 10, 2021 15:17
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 chetanraj/15e7960d6acc11695b86b53113c7d3fa to your computer and use it in GitHub Desktop.
Save chetanraj/15e7960d6acc11695b86b53113c7d3fa to your computer and use it in GitHub Desktop.
useThemeExample
function useTheme(theme) {
useLayoutEffect(
() => {
// Iterate through each value in theme object
for (const key in theme) {
// Update css variables in document's root element
document.documentElement.style.setProperty(`--${key}`, theme[key]);
}
},
[theme] // Only call again if theme object reference changes
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment