'SomeComponent' cannot be used as a JSX component.
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 18.12.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 13.0.1-canary.4
eslint-config-next: 13.0.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
Any components are producing IDE error but builds successfully.
'SomeComponent' cannot be used as a JSX component.
Its return type 'Promise<Element>' is not a valid JSX element.
Type 'Promise<Element>' is missing the following properties from type 'ReactElement<any, any>': type, props, key `ts(2786)`
Expected Behavior
probably not give an error when using async components
Link to reproduction
no link
To Reproduce
// ~/component/SomeComponent.tsx
export default async function SomeComponent() {
let categories: any = await getCategories()
return ...
}
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Component cannot be used as a JSX component. Its return ...
I'm currently getting the following error on the Todos component inside TodoApp.tsx : 'Todos' cannot be used as a JSX component.
Read more >Component cannot be used as a JSX component in React
The error Component cannot be used as a JSX component occurs for multiple reasons, returning an array of JSX elements instead of a...
Read more >cannot be used as a jsx component. its return type 'void' is not ...
I am creating a login form in react using Typescript. I have set props type as any. But i cannot import it into...
Read more >'AfterInteractions' cannot be used as a JSX component. - Reddit
How can I solve this error ? €: Error still exists <AfterInteractions placeholder={<LoaderFullScreen />}> <SomeComponent /> </AfterInteractions>.
Read more >VirtualizedList - React Native
In general, this should only really be used if you need more ... Can be a React Component (e.g. SomeComponent ), or a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think a fix is upcoming, but pretty much the issue is that TypeScript doesn’t understand async components… It always expects JSX as child, not
Promise<JSX>
.Many are type casting the component and exporting that type casted version… I think it might be better to do:
When the types are fixed, the
@ts-expect-error
directive will complain that it is unused…This fix might come from the next typescript plugin I think, not sure.
Just added a few notes about this workaround to the beta docs as well, thank you!