React API should be called with arguments of correct types

  • REACT_MISMATCHED_TYPE_OF_ARG
  • Error
  • High, Medium
  • cwe, react

This rule applies when React API is called with arguments of wrong types.

Because React API has the specification for its arguments, React will throw an error or output a warning message if the types of arguments are wrong.

Noncompliant Code Example

View with compliant examples side by side
import { createRoot } from 'react-dom/client';

function App() {
  return <div>Hello</div>;
}

const root = createRoot(document.getElementById('root'));
root.render(App); // REACT_MISMATCHED_TYPE_OF_ARG alarm because the first argument of 'render()' should be a React element.

Compliant Code Example

View with noncompliant examples side by side
import { createRoot } from 'react-dom/client';

function App() {
  return <div>Hello</div>;
}

const root = createRoot(document.getElementById('root'));
root.render(<App />);

Version

This rule was introduced in DeepScan 1.5.0-beta.

See

  • CWE-628

  • React API Reference

  • React Warning: Functions are not valid as a React child. This may happen if you return App instead of <App /> from render. Or maybe you meant to call this function rather than return it.

Was this documentation helpful?