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

And here is an article on why it's become en vogue:

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