Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Basics Introducing Props Setting and Using Props

Luke Markham
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Luke Markham
Front End Web Development Techdegree Graduate 17,289 Points

Must use destructing props assignment Eslint

const Header = props => (
  <header>
    <h1>{props.title}</h1>
    <span className="stats">{props.totalPlayers} </span>
  </header>
);

I'm getting an eslint warning on props.title & props.totalPlayers that says I should be using destructing. How would this syntax be achieved ?

1 Answer

What the error is saying is that you shouldn't be using dot notation to reference the keys inside of the props object.

You'll need to do something like this:

const Header = props => (
  const {title, totalPlayers} = props;    // <-- This is the destructuring piece. 
  <header>
    <h1>{title}</h1>
    <span className="stats">{totalPlayers} </span>
  </header>
);

Here's a good simple explainer of what exactly is going on: https://wesbos.com/destructuring-objects/