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 (retired) Thinking in Components PropTypes and DefaultProps

Are commas at the last key pairs standard practice? That feels ugly

In the video, he has

Application.propTypes = {
  title: React.PropTypes.string,
};

Application.defaultProps = {
  title: "Scoreboard",
}

I feel like that last should not have a comma. It works, but I wonder what best practice is

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I've seen this question before and some languages simply don't allow it. However, I've also seen this done in PHP. The idea here is that when you are coding and wanting to add new properties quickly, it happens (often enough) that you forget to put a comma on the previous line and start writing the next property. This, of course, results in a syntax error. I have seen several instructors do this on Treehouse and I've even seen it a bit out in the wild (though I'd be hard pressed to say exactly where).

Hope this helps!

It's a rule in the Airbnb Style Guide, and Jim works at Airbnb, so I'm guessing he's following the guide used at his company.

FWIW, I've seen Facebook React devs use this to, but I still can't get on the bandwagon. Feels weird.

Here's the ESLint rule: http://eslint.org/docs/rules/comma-dangle

And here is an article on why it's become en vogue: https://medium.com/@nikgraf/why-you-should-enforce-dangling-commas-for-multiline-statements-d034c98e36f8

I think about it and it actually makes sense. It is consistent. That being said, it still feels weird to me.