Next.js Discord

Discord Forum

Passing an object from a Component to another React

Unanswered
Rex posted this in #help-forum
Open in Discord
RexOP
Here I created an interface, an object for example (then I'll get by API), and then I try to pass this object to a React Component.
Before I've also tried passing 'category' without destructuring {} in CategoryItem parameters, but same error...

12 Replies

@Rex Try:

const CategoryItem = ({ category }: { category: CategoryInterface }) =>
RexOP
Now it shows no errors in CategoryItem, but here I got this
It means that the categoryList[0] may be undefined.
What is categoryList in your code?
@Nelson What is `categoryList` in your code?
RexOP
It's the one in the photo's post
with the objects
and then I just import it in my page.tsx
Show me the latest code of CategoryItem.tsx.
@Nelson Show me the latest code of `CategoryItem.tsx`.
RexOP
@Rex Ahh, I can't see what is wrong 😂
Try to restart your vscode?
Yea maybe it's just the possibility that the item is undefined, but since I create it, no problem, thank you 🙂