Skip to content

Commit

Permalink
handle undefined document or body
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Sep 3, 2024
1 parent d95694a commit b02f732
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/shared/ThemeContext/ThemeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ export const ThemeContextProvider: FC<ThemeContextProviderProps> = ({
const initialRender = useRef(true)

if (initialRender.current) {
document.body.classList.remove(Theme.LIGHT, Theme.DARK)
document.body.classList.add(theme)

localStorage.setItem('theme', theme)
if (typeof document !== 'undefined' && document.body) {
document.body.classList.remove(Theme.LIGHT, Theme.DARK)
document.body.classList.add(theme)
localStorage.setItem('theme', theme)
}
initialRender.current = false
}

const handleTheme = useCallback((theme: Theme) => {
document.body.classList.remove(Theme.LIGHT, Theme.DARK)
document.body.classList.add(theme)
localStorage.setItem('theme', theme)
setTheme(theme)
if (typeof document !== 'undefined' && document.body) {
document.body.classList.remove(Theme.LIGHT, Theme.DARK)
document.body.classList.add(theme)
localStorage.setItem('theme', theme)
setTheme(theme)
}
}, [])

return (
Expand Down

0 comments on commit b02f732

Please sign in to comment.