File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
import './App.css'
2
- import { useState } from 'react'
2
+ import { useState , useEffect } from 'react'
3
3
import { Routes , Route } from 'react-router-dom'
4
4
import Header from './component/Header/Header'
5
5
import Home from './pages/Home' ;
6
6
import Details from './pages/Details' ;
7
7
8
8
function App ( ) {
9
- const [ theme , setTheme ] = useState ( false ) ;
9
+ const [ theme , setTheme ] = useState ( false )
10
+ let themes ;
11
+ if ( localStorage ) {
12
+ themes = localStorage . getItem ( "theme" )
13
+ }
14
+ if ( theme == 'true' ) {
15
+ document . body . classList . add ( "dark" )
16
+ } else {
17
+ document . body . classList . remove ( "dark" )
18
+ }
19
+
10
20
const darkMode = ( ) => {
11
- document . body . classList . toggle ( 'dark' ) ;
12
21
setTheme ( ! theme )
22
+ localStorage . setItem ( "theme" , theme )
13
23
}
14
24
return (
15
25
< div className = "App dark:text-white text-[#111517]" >
You can’t perform that action at this time.
0 commit comments