question about spread operator in react

Can someone explain why I need to use the spread (...) operator when giving each post to PostCard, but i can't use it when just console logging it?
Also, if PostCard only takes 1 argument: post, why can't i just pass the entire post to PostCard, why do i need to do ...post? thanks
No description
No description
2 Replies
cje
cje13mo ago
PostCard doesn't take one argument, it takes several arguments - one for each key of the Post type. You named it post, but it's actually the root props if you wrote the function signature as function PostCard(props: { post: Post }) you could call it with <PostCard post={post} /> objects can only be spread into other objects, not into "nothing"
machina
machina13mo ago
Thanks!
Want results from more Discord servers?
Add your server