Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent usage of the return value of ReactDOM.render (react/no-render-return-value) #1568

Closed
feross opened this issue Oct 28, 2020 · 0 comments

Comments

@feross
Copy link
Member

feross commented Oct 28, 2020

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md

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 to the root element.

Source: ReactDOM documentation

Rule Details

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

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

ReactDOM.render(<App />, document.body, doSomethingWithInst);
@feross feross added this to the standard 16 milestone Oct 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

1 participant