Skip to content

Commit 04cdc36

Browse files
committed
Tweak readme
1 parent 06f38f3 commit 04cdc36

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Connects a React component to a Redux store.
230230

231231
* [`mapDispatchToProps(dispatch, [ownProps]): dispatchProps`] \(*Object* or *Function*): If an object is passed, each function inside it will be assumed to be a Redux action creator. An object with the same function names, but bound to a Redux store, will be merged into the component’s props. If a function is passed, it will be given `dispatch`. It’s up to you to return an object that somehow uses `dispatch` to bind action creators in your own way. (Tip: you may use [`bindActionCreators()`](http://gaearon.github.io/redux/docs/api/bindActionCreators.html) helper from Redux.) If you omit it, the default implementation just injects `dispatch` into your component’s props. If `ownProps` is passed in as a second argument then `mapStateToProps` will be re-invoked whenever the component receives new props.
232232

233-
* [`mergeProps(stateProps, dispatchProps, parentProps): props`] \(*Function*): If specified, it is passed the result of `mapStateToProps()`, `mapDispatchToProps()`, and the parent `props`. The plain object you return from it will be passed as props to the wrapped component. You may specify this function to select a slice of the state based on props, or to bind action creators to a particular variable from props. If you omit it, `{ ...parentProps, ...stateProps, ...dispatchProps }` is used by default.
233+
* [`mergeProps(stateProps, dispatchProps, ownProps): props`] \(*Function*): If specified, it is passed the result of `mapStateToProps()`, `mapDispatchToProps()`, and the parent `props`. The plain object you return from it will be passed as props to the wrapped component. You may specify this function to select a slice of the state based on props, or to bind action creators to a particular variable from props. If you omit it, `{ ...ownProps, ...stateProps, ...dispatchProps }` is used by default.
234234

235235
#### Returns
236236

@@ -372,6 +372,18 @@ function mapDispatchToProps(dispatch) {
372372
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
373373
```
374374

375+
##### Inject `todos` of a specific user depending on props
376+
377+
```js
378+
import * as actionCreators from './actionCreators';
379+
380+
function mapStateToProps(state, ownProps) {
381+
return { todos: state.todos[ownProps.userId] };
382+
}
383+
384+
export default connect(mapStateToProps)(TodoApp);
385+
```
386+
375387
##### Inject `todos` of a specific user depending on props, and inject `props.userId` into the action
376388

377389
```js
@@ -381,10 +393,10 @@ function mapStateToProps(state) {
381393
return { todos: state.todos };
382394
}
383395

384-
function mergeProps(stateProps, dispatchProps, parentProps) {
385-
return Object.assign({}, parentProps, {
386-
todos: stateProps.todos[parentProps.userId],
387-
addTodo: (text) => dispatchProps.addTodo(parentProps.userId, text)
396+
function mergeProps(stateProps, dispatchProps, ownProps) {
397+
return Object.assign({}, ownProps, {
398+
todos: stateProps.todos[ownProps.userId],
399+
addTodo: (text) => dispatchProps.addTodo(ownProps.userId, text)
388400
});
389401
}
390402

0 commit comments

Comments
 (0)