[Tutorial w/TypeScript] Warning: 'ArticlesCell' return type 'Element[]' not a valid JSX element.
See original GitHub issueWorking through the tutorial in TypeScript mode, VSCode complains about the ArticlesCell
return type:
Interestingly, the warning doesn’t appear while the Success
function still returns the Articles wrapped in <ul>
, it only starts appearing when we change them to render as individual <article>
s as advised at the end of https://redwoodjs.com/docs/tutorial/chapter2/cells#our-first-cell
However, wrapping <ArticlesCell />
in a fragment or a div in Homepage.tsx
does not make the warning go away.
Compilation succeeds nevertheless so it’s possible to continue the tutorial, but still it would be nice to know which type to annotate the cell with so this warning goes away.
Reporting this non-critical finding here as advised.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Component cannot be used as a JSX component. Its return ...
You need to return a JSX Element, not an array. Wrapping the whole component is a solution, but you need to do it...
Read more >Component cannot be used as a JSX component. Its ... - GitHub
I'm currently getting the following error on the Todos component inside TodoApp.tsx : 'Todos' cannot be used as a JSX component. Its return...
Read more >its return type 'element[]' is not a valid jsx element - You.com
Its return type 'Element[]' is not a valid JSX element' with React TypeScript, we need to make sure our component returns a single...
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 >Documentation - JSX - TypeScript
Type Checking · For React, intrinsic elements are emitted as strings ( React.createElement("div") ), whereas a component you've created is not ( React....
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
Typescript see success as an array of element (but I think it should be an array of component, but I don’t know if this really change something) which is not, like the error say, a valid JSX component. I wrap the map function inside a React fragment to fix this. Maybe we should have done this way in the tutorial, but I let @cannikin decide what he thinks about that.
Thanks, of course that is the obvious solution and makes the error go away 👍 … why didn’t i think of that – i did actually try React fragment around
<ArticlesCell />
but of course that’s the same difference 🤦 😆IMHO it should be done that way for the time being in chapter 2 so RedwoodJS learners are left with valid code until they get to chapter 5. I took the liberty to prepare #5020 for this.