Skip to content

Commit

Permalink
refactore toggleThemeHandler function
Browse files Browse the repository at this point in the history
Co-authored-by: Demian Parkhomenko <[email protected]>
  • Loading branch information
firehawk89 and DemianParkhomenko authored Oct 1, 2023
1 parent e5e2269 commit 928d256
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/store/theme-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ export default function ThemeProvider({ children }) {
}

const toggleThemeHandler = () => {
const theme = localStorage.getItem('theme')

if (theme) {
localStorage.setItem('theme', theme === 'dark' ? 'light' : 'dark')
} else {
localStorage.setItem('theme', 'dark')
}

setCurrentTheme(currentTheme === 'light' ? 'dark' : 'light')
const current = localStorage.getItem('theme')
const next = current === 'dark' ? 'light' : 'dark'
localStorage.setItem('theme', next)
setCurrentTheme(next)
}

return (
Expand Down

0 comments on commit 928d256

Please sign in to comment.