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 trial

JavaScript React Components (2018) React Component Patterns React Component Patterns Review

Rikki Ringgold
Rikki Ringgold
11,565 Points

Destructure 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 }) => {

bl9
bl9
34 Points

You'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:

const Book = (props) => {

}

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:

const Book = ({ title, author, year }) => {

}

You are really saying:

const Book = (props) => {
  let title = props.title;
  let author = props.author;
  let year = props.year;
}

1 Answer

Rikki Ringgold
Rikki Ringgold
11,565 Points

Ahh! Awesome! Thank you for the response and explanation.

const 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>
  );
}