File tree Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
3
import { combineReducers , createStore } from 'redux' ;
4
+ import { Provider , connect } from 'react-redux' ;
4
5
import './index.css' ;
5
6
6
7
// action types
@@ -122,15 +123,23 @@ function TodoItem({ todo, onToggleTodo }) {
122
123
) ;
123
124
}
124
125
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
- ) ;
126
+ function mapStateToProps ( state ) {
127
+ return {
128
+ todos : state . todoState ,
129
+ } ;
130
+ }
131
+
132
+ function mapDispatchToProps ( dispatch ) {
133
+ return {
134
+ onToggleTodo : id => dispatch ( doToggleTodo ( id ) ) ,
135
+ } ;
133
136
}
134
137
135
- store . subscribe ( render ) ;
136
- render ( ) ;
138
+ const ConnectedTodoApp = connect ( mapStateToProps , mapDispatchToProps ) ( TodoApp ) ;
139
+
140
+ ReactDOM . render (
141
+ < Provider store = { store } >
142
+ < ConnectedTodoApp />
143
+ </ Provider > ,
144
+ document . getElementById ( 'root' )
145
+ ) ;
You can’t perform that action at this time.
0 commit comments