-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.tsx
47 lines (37 loc) · 1.09 KB
/
Main.tsx
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
37
38
39
40
41
42
43
44
45
46
47
import React from "react";
import {useTodoActions, useTodoState} from "../redux/store";
import TodoItem from "./TodoItem";
function useCompletedIds() {
return useTodoState(selectors => selectors.getComletedIDs());
}
function useTodoIds() {
return useTodoState(selectors => selectors.getTodoIDs());
}
let ID = 1;
const Main = () => {
const actions = useTodoActions();
const todoIds = useTodoIds();
const completedIds = useCompletedIds();
return (
<div>
<div style={{padding: 10}}>
<button
onClick={() => {
actions.addTodo({id: String(ID++)});
}}
>
Add todo
</button>
</div>
<h1>TODOs</h1>
{todoIds.map(id => (
<TodoItem key={id} id={id} />
))}
<h1>Completed</h1>
{completedIds.map(id => (
<TodoItem key={id} id={id} />
))}
</div>
);
};
export default Main;