Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript says my component cannot be used as a JSX component

Error'Component' cannot be used as a JSX component.

Short answer

Before TypeScript 5.1 every JSX tag had to return exactly JSX.Element, so components returning anything wider were rejected. Update TypeScript and the React type packages to current versions. If the message is about children, React 18 types no longer add children for you: declare it in the props.

  • Applies to TypeScript 5.x, @types/react 18 and 19, React Native 0.7x, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the versions of TypeScript and the React types your editor really uses. Old versions of either are behind most of these errors.

    npx tsc --version
    npm ls @types/react
  2. 2Match what you see, then jump to its fix

    1. 1The message says the return type is not a valid JSX element, for a component that renders fine at runtimeTypeScript or the React types are older than the JSX tag-type rulesFix
    2. 2The error appears on a component that wraps other elements, and complains about the children prop or about {}The props type is missing children (React 18 types)Fix

What does the error look like?

  • 'Component' cannot be used as a JSX component.
  • Its return type 'Promise<Element>' is not a valid JSX element.
  • Type '{}' is not assignable to type 'ReactNode'

Cause 1 of 2

TypeScript or the React types are older than the JSX tag-type rules

1Check

TypeScript 5.1 stopped requiring every JSX tag to return JSX.Element and added JSX.ElementType, which the React types can fill in. On older TypeScript, a component returning a Promise or a wider type is rejected.

npx tsc --version

2Fix

Upgrade TypeScript and the React type packages.

npm install --save-dev typescript@latest @types/react@latest

3Verify

The type check passes.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 2 of 2

The props type is missing children (React 18 types)

1Check

With the React 18 types, a component receives children only when its props type lists the prop. A component typed with only its own props rejects the elements placed inside it.

grep -rn "children" src --include=*.tsx | head

2Fix

List children explicitly in the props, as the React 18 upgrade guide shows.

interface MyButtonProps {
  color: string;
  children?: React.ReactNode;
}

3Verify

The type check passes, and the component still renders its children.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Upgrade TypeScript and @types/react together, and commit the lock file.
  • Run tsc --noEmit in CI so a type error cannot reach a release build.
  • When you upgrade React, read the TypeScript section of its upgrade guide in the same sitting.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.