Skip to content

Commit 109196f

Browse files
authored
Merge pull request reduxjs#417 from erykpiast/patch-1
Add note about passing `ownProps` functions
2 parents 8b2843a + 2eb1919 commit 109196f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ Instead, it *returns* a new, connected component class, for you to use.
7272
* [`pure = true`] *(Boolean)*: If true, implements `shouldComponentUpdate` and shallowly compares the result of `mergeProps`, preventing unnecessary updates, assuming that the component is a “pure” component and does not rely on any input or state other than its props and the selected Redux store’s state. *Defaults to `true`.*
7373
* [`withRef = false`] *(Boolean)*: If true, stores a ref to the wrapped component instance and makes it available via `getWrappedInstance()` method. *Defaults to `false`.*
7474

75+
> Note: `ownProps` is passed to `mapStateToProps` and `mapDispatchToProps` only if formal definition of the function contains two mandatory parameters (function length has to be greater or equal 2). For example, functions defined like below won't receive `ownProps` as the second argument.
76+
```javascript
77+
function mapStateToProps() {
78+
console.log(arguments[0]); // state
79+
console.log(arguments[1]); // undefined
80+
}
81+
```
82+
```javascript
83+
const mapStateToProps = (...args) => {
84+
console.log(arguments[0]); // state
85+
console.log(arguments[1]); // undefined
86+
}
87+
```
88+
```javascript
89+
const mapStateToProps = (state, ownProps = {}) => {
90+
console.log(state); // state
91+
console.log(ownProps); // undefined
92+
}
93+
```
94+
7595
#### Returns
7696

7797
A React component class that injects state and action creators into your component according to the specified options.

0 commit comments

Comments
 (0)