Next.js Discord

Discord Forum

Not a valid JSX element type

Unanswered
Shih Tzu posted this in #help-forum
Open in Discord
Shih TzuOP
Anybody got an idea what could cause this?

Using latest versions of react:
react@18.2.0
react-dom@18.2.0
@types/react@18.2.12
@types/react-dom@18.2.5

12 Replies

European Turtle-Dove
show MyComponent code
Shih TzuOP
Asiatic Lion
you probably want to use React.ReactNode instead of React.JSX.Element
the entirety of this is weird
what are you actually trying to do
@Asiatic Lion you probably want to use `React.ReactNode` instead of `React.JSX.Element`
Shih TzuOP
The types are inherited and not defined by me
@DirtyCajunRice | AppDir what are you actually trying to do
Shih TzuOP
Defining React components in a node environment
@Shih Tzu The types are inherited and not defined by me
Asiatic Lion
what are they inherited by?
@Asiatic Lion what are they inherited by?
Shih TzuOP
I initially thought by react itself but there might be a library messing with the global definitions. I'll check that
Shih TzuOP
Ok, yes they are altered by another library. But more importantly: Why is React.JSX.Element not a valid type?
Asiatic Lion
it is a valid type, but React.JSX.Element is an object {} and not a react node <>{...}</>
React Elements are an object containing props, etc. while React.FC is a function component and React.ReactNode is the return value of a function component. You should use ReactNode or FC