-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc8d2b8
commit f959d20
Showing
4 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
// Provider.tsx | ||
'use client'; | ||
import { ThemeProvider } from 'next-themes'; | ||
|
||
const Providers = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<ThemeProvider enableSystem={true} attribute='class'> | ||
{children} | ||
</ThemeProvider> | ||
); | ||
return <ThemeProvider attribute='class'>{children}</ThemeProvider>; | ||
}; | ||
|
||
export default Providers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,50 @@ | ||
'use client'; | ||
import { useTheme } from 'next-themes'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
const UseThemeCheck = () => { | ||
const [isDarkMode, setIsDarkMode] = useState<boolean>(false); | ||
const { theme, setTheme } = useTheme(); | ||
const [isDarkMode, setIsDarkMode] = useState(theme === 'dark'); | ||
|
||
useEffect(() => { | ||
setIsDarkMode(theme === 'dark'); | ||
}, [theme]); | ||
|
||
const toggleTheme = () => { | ||
const theme = localStorage.getItem('theme'); | ||
setTheme(isDarkMode ? 'light' : 'dark'); | ||
}; | ||
|
||
setIsDarkMode(!isDarkMode); | ||
return { | ||
isDarkMode, | ||
toggleTheme, | ||
}; | ||
// const [isDarkMode, setIsDarkMode] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
const storedTheme = localStorage.getItem('theme'); | ||
// const toggleTheme = () => { | ||
// const theme = localStorage.getItem('theme'); | ||
|
||
// setIsDarkMode(!isDarkMode); | ||
// }; | ||
|
||
// useEffect(() => { | ||
// const storedTheme = localStorage.getItem('theme'); | ||
|
||
if (storedTheme === 'dark' || (!storedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
setIsDarkMode(true); | ||
} else { | ||
setIsDarkMode(false); | ||
} | ||
// if (storedTheme === 'dark' || (!storedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | ||
// setIsDarkMode(true); | ||
// } else { | ||
// setIsDarkMode(false); | ||
// } | ||
|
||
// 추가: 다크모드 토글 이벤트 리스너 등록 | ||
window.addEventListener('darkModeToggle', toggleTheme); | ||
// // 추가: 다크모드 토글 이벤트 리스너 등록 | ||
// window.addEventListener('darkModeToggle', toggleTheme); | ||
|
||
return () => { | ||
// 클린업: 컴포넌트 언마운트 시 리스너 제거 | ||
window.removeEventListener('darkModeToggle', toggleTheme); | ||
}; | ||
}, [isDarkMode]); | ||
// return () => { | ||
// // 클린업: 컴포넌트 언마운트 시 리스너 제거 | ||
// window.removeEventListener('darkModeToggle', toggleTheme); | ||
// }; | ||
// }, [isDarkMode]); | ||
|
||
return isDarkMode; | ||
// return isDarkMode; | ||
}; | ||
|
||
export default UseThemeCheck; |