DEV Community

Discussion on: 🎨 Light mode e Dark mode e temas customizados com Styled-components e NextJS com Typescript.

Collapse
 
marciofariagit profile image
Marcio Faria

Para persistir a categoria de tema, deixar salvo no localStorage.

const toggleTheme = () => {
if (theme.title === 'light') {
setTheme(combineTheme(dark))
localStorage.setItem('theme', 'dark')
}
if (theme.title === 'dark') {
setTheme(combineTheme(light))
localStorage.setItem('theme', 'light')
}
}

useEffect(() => {
function checkTheme() {
const typeTheme = localStorage.getItem('theme')
if (typeTheme != 'light') {
setTheme(combineTheme(dark))
}
if (typeTheme != 'dark') {
setTheme(combineTheme(light))
}
}

está bem basico, mas assim que puder eu atualizo.