Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRikki Ringgold
11,565 PointsDestructure the props passed to Book and display their values in the JSX.
Not exactly sure how to answer this question with the arrow function.
const Book = ({ title, author, published }) => {
1 Answer
Rikki Ringgold
11,565 PointsAhh! Awesome! Thank you for the response and explanation.
Muhammad Anwar Ul Haq
Full Stack JavaScript Techdegree Graduate 18,781 Pointsconst Shelf = () => {
return <Book title="TL;DR" author="Jay McQuery" year={2013} />;
}
// Book component
const Book = ({ title, author, year }) => {
return (
<div>
<h1>Title: { title }</h1>
<p>Author: { author }</p>
<p>Published: { year }</p>
</div>
);
}
bl9
34 Pointsbl9
34 PointsYou're on the right track. Destructuring is a shortcut that allows you to assign the values of an object to the corresponding keys you list.
The Book function is passed the 'props' object as an argument (that's how React works).
So really it's:
where props is equal to an object with the keys 'title', 'author, and 'year' (taken from the top line where <Book.../> is used.
When you write:
You are really saying: