Skip to content

Commit

Permalink
Add no-render-return-value documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jun 5, 2016
1 parent 06f15ed commit dae6761
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The plugin has a [recommended configuration](#user-content-recommended-configura
* [no-direct-mutation-state](docs/rules/no-direct-mutation-state.md): Prevent direct mutation of `this.state`
* [no-is-mounted](docs/rules/no-is-mounted.md): Prevent usage of `isMounted`
* [no-multi-comp](docs/rules/no-multi-comp.md): Prevent multiple component definition per file
* [no-render-return-value](docs/rules/no-render-return-value.md): Prevent usage of the return value of `React.render`
* [no-set-state](docs/rules/no-set-state.md): Prevent usage of `setState`
* [no-string-refs](docs/rules/no-string-refs.md): Prevent using string references in `ref` attribute.
* [no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
Expand Down
24 changes: 24 additions & 0 deletions docs/rules/no-render-return-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Prevent usage of the return value of React.render (no-render-return-value)

> `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.
Source: [React Top-Level API documentation](http://facebook.github.io/react/docs/top-level-api.html#reactdom.render)

## Rule Details

This rule will warn you if you try to use the `ReactDOM.render()` return value.

The following pattern is considered warning:

```js
const inst = ReactDOM.render(<App />, document.body);
doSomethingWithInst(inst);
```

The following patterns are not considered warning:

```js
ReactDOM.render(<App ref={doSomethingWithInst} />, document.body);

ReactDOM.render(<App />, document.body, doSomethingWithInst);
```

0 comments on commit dae6761

Please sign in to comment.