Skip to content

Commit dae6761

Browse files
committed
Add no-render-return-value documentation
1 parent 06f15ed commit dae6761

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ The plugin has a [recommended configuration](#user-content-recommended-configura
8383
* [no-direct-mutation-state](docs/rules/no-direct-mutation-state.md): Prevent direct mutation of `this.state`
8484
* [no-is-mounted](docs/rules/no-is-mounted.md): Prevent usage of `isMounted`
8585
* [no-multi-comp](docs/rules/no-multi-comp.md): Prevent multiple component definition per file
86+
* [no-render-return-value](docs/rules/no-render-return-value.md): Prevent usage of the return value of `React.render`
8687
* [no-set-state](docs/rules/no-set-state.md): Prevent usage of `setState`
8788
* [no-string-refs](docs/rules/no-string-refs.md): Prevent using string references in `ref` attribute.
8889
* [no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)

docs/rules/no-render-return-value.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Prevent usage of the return value of React.render (no-render-return-value)
2+
3+
> `ReactDOM.render()` currently returns a reference to the root `ReactComponent` instance. However, using this return value is legacy and should be avoided because future versions of React may render components asynchronously in some cases. If you need a reference to the root `ReactComponent` instance, the preferred solution is to attach a [callback ref](http://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute) to the root element.
4+
5+
Source: [React Top-Level API documentation](http://facebook.github.io/react/docs/top-level-api.html#reactdom.render)
6+
7+
## Rule Details
8+
9+
This rule will warn you if you try to use the `ReactDOM.render()` return value.
10+
11+
The following pattern is considered warning:
12+
13+
```js
14+
const inst = ReactDOM.render(<App />, document.body);
15+
doSomethingWithInst(inst);
16+
```
17+
18+
The following patterns are not considered warning:
19+
20+
```js
21+
ReactDOM.render(<App ref={doSomethingWithInst} />, document.body);
22+
23+
ReactDOM.render(<App />, document.body, doSomethingWithInst);
24+
```

0 commit comments

Comments
 (0)