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 Basics (2018) 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/