Using the return value of ReactDOM.render() should be avoided

  • REACT_ASYNC_RENDER_RETURN_VALUE
  • Code Quality
  • Low
  • react

This rule applies when the return value of ReactDOM.render() is used.

ReactDOM.render() currently returns a reference to the root React component instance. However, using this return value is legacy and should be avoided because future versions of React may render components asynchronously in some cases.

For more information, please see ReactDOM.render().

Noncompliant Code Example

View with compliant examples side by side
const instance = ReactDOM.render(<App />, rootElement);
foo(instance); // REACT_ASYNC_RENDER_RETURN_VALUE alarm

Compliant Code Example

View with noncompliant examples side by side
function cb(instance) {
}
// Attach a callback ref to get a return value
ReactDOM.render(<App ref={cb} />, rootElement);

Version

This rule was introduced in DeepScan 1.2.0-alpha.

See

Was this documentation helpful?