I am trying to understand this functional component in react. I know Post accepts two parameters post and excerpt. 2 tenary operators were used
Here is the render code from a component that uses post.
const renderPosts = () => {
if (loading) return <p>Loading posts...</p>
if (hasErrors) return <p>Unable to display posts.</p>
return posts.map(post => <Post key={post.id} post={post} excerpt />)
}
I don't understand what (excerpt &&) is doing together with the Link below. Can you explain this to me? Also passing excerpt from the map helper above, what does that imply? It has no value.
export const Post = ({ post, excerpt }) => (
<article className={excerpt ? 'post-excerpt' : 'post'}>
<h2>{post.title}</h2>
<p>{excerpt ? post.body.substring(0, 100) : post.body}</p>
{excerpt && (
<Link to={`/posts/${post.id}`} className="button">
View Post
</Link>
)}
</article>
)