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 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,23 @@ 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+ 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+ } ;
133136}
134137
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