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!

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 Components (2018) Managing State and Data Flow Adding Items to State

Joseph Michelini
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Michelini
Python Development Techdegree Graduate 18,692 Points

What are the syntax rules for adding component properties in React?

At some point in the video, we initialize a property prevPlayerId in App.js to 4. The syntax caught me a little off-guard, because we use a = to initialize it, and I'm used to using : to initialize properties on objects and classes. Is this similar to calling the App component and adding the property in-line, except in this case we're adding it in the class definition?

Thanks in advance!

1 Answer

Hey Joseph,

I think I'm understanding your question correctly and believe I have the answer. We can initialize properties of the component by declaring them and initializing them this way. This is similar to the way we initialize the state of the App. The only difference is with state we are creating an object while prevPlayerId is just initializing a number.

I submit this answer with the caveat that I am only mostly sure that I've got it right. Haha. This is just the way that seemed to make sense to me.

Happy coding!