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

Brian Patrick
PLUS
Brian Patrick
Courses Plus Student 2,770 Points

When designating propTypes why do we include a coma at the end of the object if there is only one key?

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

2 Answers

Andrew Hickman
seal-mask
.a{fill-rule:evenodd;}techdegree
Andrew Hickman
Full Stack JavaScript Techdegree Student 10,013 Points

Hey Brian! It's not necessary to type a trailing comma. It's just become conventional, because it's easier to reorder properties and debug if you don't have to worry about you or someone else leaving that comma out. Whatever floats your boat. Do whatever is more convenient for you.

Robert Schaap
Robert Schaap
19,836 Points

Like Andrew mentioned, it isn't necessary but another good reason is when you're using git and someone else is reviewing changes you made to the code in a project.

If your line already ended with a comma and you hit enter to insert a new line, the reviewer will see only 1 change: the line you added. If you also added a comma on the line above, that line will also be shown as changed, though technically it didn't. In bigger files many small changes like that make it hard for a reviewer to see what actually changed and what's just spacing/commas etc.