Skip to content

Commit ac12598

Browse files
authored
Merge pull request reduxjs#420 from erykpiast/patch-2
Correct `ownProps` note and examples
2 parents 109196f + 91b548e commit ac12598

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

docs/api.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,39 @@ 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.
75+
> Note: `ownProps` **is not passed** to `mapStateToProps` and `mapDispatchToProps` if formal definition of the function contains one mandatory parameter (function has length 1). For example, function defined like below won't receive `ownProps` as the second argument.
7676
```javascript
77-
function mapStateToProps() {
78-
console.log(arguments[0]); // state
77+
function mapStateToProps(state) {
78+
console.log(state); // state
7979
console.log(arguments[1]); // undefined
8080
}
8181
```
8282
```javascript
83-
const mapStateToProps = (...args) => {
84-
console.log(arguments[0]); // state
85-
console.log(arguments[1]); // undefined
83+
const mapStateToProps = (state, ownProps = {}) => {
84+
console.log(state); // state
85+
console.log(ownProps); // undefined
8686
}
8787
```
88+
Functions with no mandatory parameters or two parameters **will receive** `ownProps`.
8889
```javascript
89-
const mapStateToProps = (state, ownProps = {}) => {
90+
const mapStateToProps = (state, ownProps) => {
9091
console.log(state); // state
91-
console.log(ownProps); // undefined
92+
console.log(ownProps); // ownProps
9293
}
9394
```
95+
```javascript
96+
function mapStateToProps() {
97+
console.log(arguments[0]); // state
98+
console.log(arguments[1]); // ownProps
99+
}
100+
```
101+
```javascript
102+
const mapStateToProps = (...args) => {
103+
console.log(arguments[0]); // state
104+
console.log(arguments[1]); // ownProps
105+
}
106+
```
107+
94108

95109
#### Returns
96110

0 commit comments

Comments
 (0)