-
-
Save devpikachu/532256d53023a9ae4e71fed520a61a96 to your computer and use it in GitHub Desktop.
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
import '../styles/globals.css'; | |
import { CssBaseline, ThemeProvider } from '@nextui-org/react'; | |
import useDarkMode from 'use-dark-mode'; | |
import { useEffect } from 'react'; | |
import React from 'react'; | |
import sharedTheme from '@nextui-org/react/cjs/theme/shared'; | |
function IdentityApp({ Component, pageProps }) { | |
const [theme, setTheme] = React.useState({ | |
...sharedTheme | |
}); | |
const themeChangeHandle = (isDark) => { | |
if (theme.type === 'dark' && !isDark) { | |
setTheme({ | |
...theme, | |
type: "light" | |
}); | |
} else if (theme.type === 'light' && isDark) { | |
setTheme({ | |
...theme, | |
type: "dark" | |
}); | |
} | |
}; | |
const darkMode = useDarkMode(true, { | |
onChange: themeChangeHandle | |
}); | |
useEffect(() => { | |
const savedTheme = window.localStorage.getItem('darkMode') ? 'dark' : 'light'; | |
setTheme((prevTheme) => ({ | |
...prevTheme, | |
type: savedTheme || 'dark' | |
})); | |
}, []); | |
return ( | |
<> | |
<ThemeProvider theme={theme}> | |
<CssBaseline /> | |
<Component {...pageProps} /> | |
</ThemeProvider> | |
</> | |
); | |
} | |
export default IdentityApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment