JavaScript React Components React Component Patterns React Component Patterns Review

Rikki Ringgold
Rikki Ringgold
11,563 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,563 Points

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