File tree Expand file tree Collapse file tree 1 file changed +44
-3
lines changed Expand file tree Collapse file tree 1 file changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -88,8 +88,49 @@ const store = createStore(rootReducer);
88
88
89
89
// view layer
90
90
91
- function TodoApp ( ) {
92
- return < div > Todo App</ div > ;
91
+ function TodoApp ( { todos, onToggleTodo } ) {
92
+ return < TodoList
93
+ todos = { todos }
94
+ onToggleTodo = { onToggleTodo }
95
+ /> ;
93
96
}
94
97
95
- ReactDOM . render ( < TodoApp /> , document . getElementById ( 'root' ) ) ;
98
+ function TodoList ( { todos, onToggleTodo } ) {
99
+ return (
100
+ < div >
101
+ { todos . map ( todo => < TodoItem
102
+ key = { todo . id }
103
+ todo = { todo }
104
+ onToggleTodo = { onToggleTodo }
105
+ /> ) }
106
+ </ div >
107
+ ) ;
108
+ }
109
+
110
+ function TodoItem ( { todo, onToggleTodo } ) {
111
+ const { name, id, completed } = todo ;
112
+ return (
113
+ < div >
114
+ { name }
115
+ < button
116
+ type = "button"
117
+ onClick = { ( ) => onToggleTodo ( id ) }
118
+ >
119
+ { completed ? "Incomplete" : "Complete" }
120
+ </ button >
121
+ </ div >
122
+ ) ;
123
+ }
124
+
125
+ function render ( ) {
126
+ ReactDOM . render (
127
+ < TodoApp
128
+ todos = { store . getState ( ) . todoState }
129
+ onToggleTodo = { id => store . dispatch ( doToggleTodo ( id ) ) }
130
+ /> ,
131
+ document . getElementById ( 'root' )
132
+ ) ;
133
+ }
134
+
135
+ store . subscribe ( render ) ;
136
+ render ( ) ;
You can’t perform that action at this time.
0 commit comments