React is saying a function can not be passed as a child

Hello, I am trying to render a list of components on one of my pages, however when doing so I am getting the following error: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it. Any idea why this could be? Thanks for the help!
<div className="w-full h-full pt-[600px] max-w-[1000px] mx-auto grid grid-cols-3">
{() => {
let sponsorCards = [];
for (const sponsor of props.sponsors) {
console.log('Sponsor Data: ', sponsor);
sponsorCards.push(<SponsorCard {...sponsor} />);
}
return sponsorCards;
}}
</div>
<div className="w-full h-full pt-[600px] max-w-[1000px] mx-auto grid grid-cols-3">
{() => {
let sponsorCards = [];
for (const sponsor of props.sponsors) {
console.log('Sponsor Data: ', sponsor);
sponsorCards.push(<SponsorCard {...sponsor} />);
}
return sponsorCards;
}}
</div>
7 Replies
Valhalaar
Valhalaar•2y ago
If you want to inline a function like this it has to be an IIFE
{
{(() => {})()}
}
{
{(() => {})()}
}
you have to call it inline like that
JacobMGEvans
JacobMGEvans•2y ago
Side note you can put switches in that lol Inline state reducer 🤣🤣🤣
Liam
LiamOP•2y ago
That makes total sense, don't know why I didn't think of that. Thanks!
Valhalaar
Valhalaar•2y ago
sure thing!
JacobMGEvans
JacobMGEvans•2y ago
Are you learning?
Liam
LiamOP•2y ago
No, just my brain forgets stuff sometimes lmao
JacobMGEvans
JacobMGEvans•2y ago
Glad this helped then!!
Want results from more Discord servers?
Add your server