File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change 8
8
"dependencies" : {
9
9
"react" : " ^15.5.4" ,
10
10
"react-dom" : " ^15.5.4" ,
11
+ "react-redux" : " ^5.0.5" ,
11
12
"redux" : " ^3.6.0"
12
13
},
13
14
"scripts" : {
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,25 @@ 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
+ // Connecting React and Redux
127
+
128
+ function mapStateToProps ( state ) {
129
+ return {
130
+ todos : state . todoState ,
131
+ } ;
133
132
}
134
133
135
- store . subscribe ( render ) ;
136
- render ( ) ;
134
+ function mapDispatchToProps ( dispatch ) {
135
+ return {
136
+ onToggleTodo : id => dispatch ( doToggleTodo ( id ) ) ,
137
+ } ;
138
+ }
139
+
140
+ const ConnectedTodoApp = connect ( mapStateToProps , mapDispatchToProps ) ( TodoApp ) ;
141
+
142
+ ReactDOM . render (
143
+ < Provider store = { store } >
144
+ < ConnectedTodoApp />
145
+ </ Provider > ,
146
+ document . getElementById ( 'root' )
147
+ ) ;
You can’t perform that action at this time.
0 commit comments