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 88 "dependencies" : {
99 "react" : " ^15.5.4" ,
1010 "react-dom" : " ^15.5.4" ,
11+ "react-redux" : " ^5.0.5" ,
1112 "redux" : " ^3.6.0"
1213 },
1314 "scripts" : {
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import ReactDOM from 'react-dom' ;
33import { combineReducers , createStore } from 'redux' ;
4+ import { Provider , connect } from 'react-redux' ;
45import './index.css' ;
56
67// action types
@@ -122,15 +123,25 @@ function TodoItem({ todo, onToggleTodo }) {
122123 ) ;
123124}
124125
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+ } ;
133132}
134133
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