Skip to content

Commit

Permalink
�Add validation to ensure the validity of themeName from localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
devITae committed Dec 23, 2024
1 parent 651dba4 commit 33f0002
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app/context/ThemeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

export const enum THEME {
export enum THEME {
LIGHT = 'light',
DARK = 'dark',
CHRISTMAS = 'christmas',
Expand All @@ -22,7 +22,11 @@ export const useDarkmodeContext = () => {
export const DarkmodeContextProvider = ({
children,
}: React.PropsWithChildren) => {
const themeName = window.localStorage.getItem('theme') as THEME || THEME.LIGHT
const themeName =
Object
.values(THEME)
.includes(window.localStorage.getItem('theme') as THEME)
? window.localStorage.getItem('theme') as THEME : THEME.LIGHT
const [theme, setTheme] = React.useState<THEME>(themeName)

return (
Expand Down

0 comments on commit 33f0002

Please sign in to comment.