Skip to content

Commit 1b49bbe

Browse files
committed
Add allow-in-func option to no-did-update-set-state documentation
1 parent a65f038 commit 1b49bbe

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/rules/no-did-update-set-state.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,47 @@ var Hello = React.createClass({
3131
}
3232
});
3333
```
34+
35+
## Rule Options
36+
37+
```js
38+
...
39+
"no-did-update-set-state": [<enabled>, <mode>]
40+
...
41+
```
42+
43+
### `allow-in-func` mode
44+
45+
By default this rule forbids any call to `this.setState` in `componentDidUpdate`. But in certain cases you may need to perform asynchronous calls in `componentDidUpdate` that may end up with calls to `this.setState`. The `allow-in-func` mode allows you to use `this.setState` in `componentDidUpdate` as long as they are called within a function.
46+
47+
The following patterns are considered warnings:
48+
49+
```js
50+
var Hello = React.createClass({
51+
componentDidUpdate: function() {
52+
this.setState({
53+
name: this.props.name.toUpperCase()
54+
});
55+
},
56+
render: function() {
57+
return <div>Hello {this.state.name}</div>;
58+
}
59+
});
60+
```
61+
62+
The following patterns are not considered warnings:
63+
64+
```js
65+
var Hello = React.createClass({
66+
componentDidUpdate: function() {
67+
this.onUpdate(function callback(newName) {
68+
this.setState({
69+
name: newName
70+
});
71+
});
72+
},
73+
render: function() {
74+
return <div>Hello {this.state.name}</div>;
75+
}
76+
});
77+
```

0 commit comments

Comments
 (0)