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
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](https://cdn.answeroverflow.com/1151074119958409267/image.png)
![No description](https://cdn.answeroverflow.com/1151074120231043143/image.png)
2 Replies
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"Thanks!