@@ -21,7 +21,7 @@ ReactDOM.render(
2121 < MyRootComponent / >
2222 < / Provider> ,
2323 rootEl
24- );
24+ )
2525```
2626
2727##### React Router 0.13
@@ -34,8 +34,8 @@ Router.run(routes, Router.HistoryLocation, (Handler, routerState) => { // note "
3434 < Handler routerState= {routerState} / >
3535 < / Provider> ,
3636 document .getElementById (' root' )
37- );
38- });
37+ )
38+ })
3939```
4040
4141##### React Router 1.0
@@ -46,7 +46,7 @@ ReactDOM.render(
4646 < Router history= {history}> ... < / Router>
4747 < / Provider> ,
4848 targetEl
49- );
49+ )
5050```
5151
5252### ` connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options]) `
@@ -99,7 +99,7 @@ Returns the wrapped component instance. Only available if you pass `{ withRef: t
9999##### Inject just ` dispatch ` and don't listen to store
100100
101101``` js
102- export default connect ()(TodoApp);
102+ export default connect ()(TodoApp)
103103```
104104
105105##### Inject ` dispatch ` and every field in the global state
@@ -109,151 +109,151 @@ export default connect()(TodoApp);
109109> listen to a relevant slice of the state.
110110
111111``` js
112- export default connect (state => state)(TodoApp);
112+ export default connect (state => state)(TodoApp)
113113```
114114
115115##### Inject ` dispatch ` and ` todos `
116116
117117``` js
118118function mapStateToProps (state ) {
119- return { todos: state .todos };
119+ return { todos: state .todos }
120120}
121121
122- export default connect (mapStateToProps)(TodoApp);
122+ export default connect (mapStateToProps)(TodoApp)
123123```
124124
125125##### Inject ` todos ` and all action creators (` addTodo ` , ` completeTodo ` , ...)
126126
127127``` js
128- import * as actionCreators from ' ./actionCreators' ;
128+ import * as actionCreators from ' ./actionCreators'
129129
130130function mapStateToProps (state ) {
131- return { todos: state .todos };
131+ return { todos: state .todos }
132132}
133133
134- export default connect (mapStateToProps, actionCreators)(TodoApp);
134+ export default connect (mapStateToProps, actionCreators)(TodoApp)
135135```
136136
137137##### Inject ` todos ` and all action creators (` addTodo ` , ` completeTodo ` , ...) as ` actions `
138138
139139``` js
140- import * as actionCreators from ' ./actionCreators' ;
141- import { bindActionCreators } from ' redux' ;
140+ import * as actionCreators from ' ./actionCreators'
141+ import { bindActionCreators } from ' redux'
142142
143143function mapStateToProps (state ) {
144- return { todos: state .todos };
144+ return { todos: state .todos }
145145}
146146
147147function mapDispatchToProps (dispatch ) {
148- return { actions: bindActionCreators (actionCreators, dispatch) };
148+ return { actions: bindActionCreators (actionCreators, dispatch) }
149149}
150150
151- export default connect (mapStateToProps, mapDispatchToProps)(TodoApp);
151+ export default connect (mapStateToProps, mapDispatchToProps)(TodoApp)
152152```
153153
154154##### Inject ` todos ` and a specific action creator (` addTodo ` )
155155
156156``` js
157- import { addTodo } from ' ./actionCreators' ;
158- import { bindActionCreators } from ' redux' ;
157+ import { addTodo } from ' ./actionCreators'
158+ import { bindActionCreators } from ' redux'
159159
160160function mapStateToProps (state ) {
161- return { todos: state .todos };
161+ return { todos: state .todos }
162162}
163163
164164function mapDispatchToProps (dispatch ) {
165- return bindActionCreators ({ addTodo }, dispatch);
165+ return bindActionCreators ({ addTodo }, dispatch)
166166}
167167
168- export default connect (mapStateToProps, mapDispatchToProps)(TodoApp);
168+ export default connect (mapStateToProps, mapDispatchToProps)(TodoApp)
169169```
170170
171171##### Inject ` todos ` , todoActionCreators as ` todoActions ` , and counterActionCreators as ` counterActions `
172172
173173``` js
174- import * as todoActionCreators from ' ./todoActionCreators' ;
175- import * as counterActionCreators from ' ./counterActionCreators' ;
176- import { bindActionCreators } from ' redux' ;
174+ import * as todoActionCreators from ' ./todoActionCreators'
175+ import * as counterActionCreators from ' ./counterActionCreators'
176+ import { bindActionCreators } from ' redux'
177177
178178function mapStateToProps (state ) {
179- return { todos: state .todos };
179+ return { todos: state .todos }
180180}
181181
182182function mapDispatchToProps (dispatch ) {
183183 return {
184184 todoActions: bindActionCreators (todoActionCreators, dispatch),
185185 counterActions: bindActionCreators (counterActionCreators, dispatch)
186- };
186+ }
187187}
188188
189- export default connect (mapStateToProps, mapDispatchToProps)(TodoApp);
189+ export default connect (mapStateToProps, mapDispatchToProps)(TodoApp)
190190```
191191
192192##### Inject ` todos ` , and todoActionCreators and counterActionCreators together as ` actions `
193193
194194``` js
195- import * as todoActionCreators from ' ./todoActionCreators' ;
196- import * as counterActionCreators from ' ./counterActionCreators' ;
197- import { bindActionCreators } from ' redux' ;
195+ import * as todoActionCreators from ' ./todoActionCreators'
196+ import * as counterActionCreators from ' ./counterActionCreators'
197+ import { bindActionCreators } from ' redux'
198198
199199function mapStateToProps (state ) {
200- return { todos: state .todos };
200+ return { todos: state .todos }
201201}
202202
203203function mapDispatchToProps (dispatch ) {
204204 return {
205205 actions: bindActionCreators (Object .assign ({}, todoActionCreators, counterActionCreators), dispatch)
206- };
206+ }
207207}
208208
209- export default connect (mapStateToProps, mapDispatchToProps)(TodoApp);
209+ export default connect (mapStateToProps, mapDispatchToProps)(TodoApp)
210210```
211211
212212##### Inject ` todos ` , and all todoActionCreators and counterActionCreators directly as props
213213
214214``` js
215- import * as todoActionCreators from ' ./todoActionCreators' ;
216- import * as counterActionCreators from ' ./counterActionCreators' ;
217- import { bindActionCreators } from ' redux' ;
215+ import * as todoActionCreators from ' ./todoActionCreators'
216+ import * as counterActionCreators from ' ./counterActionCreators'
217+ import { bindActionCreators } from ' redux'
218218
219219function mapStateToProps (state ) {
220- return { todos: state .todos };
220+ return { todos: state .todos }
221221}
222222
223223function mapDispatchToProps (dispatch ) {
224- return bindActionCreators (Object .assign ({}, todoActionCreators, counterActionCreators), dispatch);
224+ return bindActionCreators (Object .assign ({}, todoActionCreators, counterActionCreators), dispatch)
225225}
226226
227- export default connect (mapStateToProps, mapDispatchToProps)(TodoApp);
227+ export default connect (mapStateToProps, mapDispatchToProps)(TodoApp)
228228```
229229
230230##### Inject ` todos ` of a specific user depending on props
231231
232232``` js
233- import * as actionCreators from ' ./actionCreators' ;
233+ import * as actionCreators from ' ./actionCreators'
234234
235235function mapStateToProps (state , ownProps ) {
236- return { todos: state .todos [ownProps .userId ] };
236+ return { todos: state .todos [ownProps .userId ] }
237237}
238238
239- export default connect (mapStateToProps)(TodoApp);
239+ export default connect (mapStateToProps)(TodoApp)
240240```
241241
242242##### Inject ` todos ` of a specific user depending on props, and inject ` props.userId ` into the action
243243
244244``` js
245- import * as actionCreators from ' ./actionCreators' ;
245+ import * as actionCreators from ' ./actionCreators'
246246
247247function mapStateToProps (state ) {
248- return { todos: state .todos };
248+ return { todos: state .todos }
249249}
250250
251251function mergeProps (stateProps , dispatchProps , ownProps ) {
252252 return Object .assign ({}, ownProps, {
253253 todos: stateProps .todos [ownProps .userId ],
254254 addTodo : (text ) => dispatchProps .addTodo (ownProps .userId , text)
255- });
255+ })
256256}
257257
258- export default connect (mapStateToProps, actionCreators, mergeProps)(TodoApp);
258+ export default connect (mapStateToProps, actionCreators, mergeProps)(TodoApp)
259259```
0 commit comments