Skip to content

Commit

Permalink
Move localStorage getTheme into useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Apr 19, 2024
1 parent 11c08d1 commit e996360
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ThemeContext = createContext<ThemeContextValue | null>(null)

export const ThemeProvider = (props: PropsWithChildren<ThemeProviderProps>) => {
const [theme, setTheme] = useState<Theme | ThemeOverrides>(
props.theme || getTheme(props.scope)
props.theme || DEFAULT_THEME
)

useEffect(() => {
Expand All @@ -74,6 +74,13 @@ export const ThemeProvider = (props: PropsWithChildren<ThemeProviderProps>) => {
window.document.documentElement.classList.add('is-apple')
}, [])

// Load theme from local storage
useEffect(() => {
if (!props.theme) {
setTheme(getTheme(props.scope))
}
}, [])

// Allow prop theme override
useEffect(() => {
if (props.theme) {
Expand Down

0 comments on commit e996360

Please sign in to comment.