-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
36 lines (30 loc) · 909 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import './App.css'
import { useEffect } from 'react'
import { useStore, useSettings } from './store';
import AsyncTodos from './components/AsyncTodos';
import Todos from './components/Todos';
import Form from './components/Form';
function App() {
const removeAllTodos = useStore(state => state.removeAllTodos)
const dark = useSettings(state => state.dark)
const toggleDarkMode = useSettings(state => state.toggleDarkMode)
useEffect(() => {
if (dark) {
document.querySelector('body').classList.add('dark')
} else {
document.querySelector('body').classList.remove('dark')
}
}, [dark])
return (
<div className="App">
<h1>Hello Zustand</h1>
<button onClick={toggleDarkMode}>Toggle theme</button>
<button onClick={removeAllTodos}>Clear all</button>
<Form />
<Todos />
<hr />
<AsyncTodos />
</div>
)
}
export default App