Report #58725
[bug\_fix] 'Component' cannot be used as a JSX component. Its return type 'ReactElement \| null' is not a valid JSX element
Upgrade \`@types/react\` to version 18.x and remove explicit \`React.ReactElement\` return type annotations from functional components, allowing TypeScript to infer the return type, or use \`React.FC\` \(or \`React.FC>\`\) which correctly types the return value for React 18. The root cause is that React 18 introduced stricter types for JSX elements. The global \`JSX.Element\` type definition changed to require specific generic parameters that \`ReactElement\` \(from older type definitions\) no longer satisfies. Components explicitly typed to return \`React.ReactElement\` \(without the proper generic defaults\) or using older \`@types/react\` versions \(17.x\) produce a return type that is incompatible with the new \`JSX.Element\` type, causing the error when the component is used in JSX.
Journey Context:
Developer upgrades a production React application from version 17 to version 18. After running \`npm install react@18 react-dom@18\` and updating \`@types/react\` and \`@types/react-dom\` to the latest versions, they restart the TypeScript server. Immediately, hundreds of components show the error: "'MyComponent' cannot be used as a JSX component. Its return type 'ReactElement \| null' is not a valid JSX element.". The developer examines a simple functional component: \`const MyComponent = \(\): React.ReactElement => Hello
;\`. This pattern worked perfectly in React 17. They try removing the explicit return type annotation, changing it to \`const MyComponent = \(\) => Hello
;\`, and the error disappears. Confused why the explicit type breaks, they investigate the React 18 migration guide. They learn that React 18's type definitions changed \`JSX.Element\` to be more strict, and the \`ReactElement\` type now requires specific generic parameters that the older usage \`React.ReactElement\` \(which defaulted to \`any\`\) no longer matches correctly. The explicit return type annotation was forcing the component to return a type that the new JSX factory rejects. The developer refactors the codebase to remove explicit \`React.ReactElement\` return types, relying on TypeScript inference, or switches to \`React.FC\` \(which correctly types the return value for React 18\). The journey highlights that React 18's stricter types often break explicit return type annotations that were common in React 17 codebases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:03:25.826383+00:00— report_created — created