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) Stateful Components Creating a Component Class

fredyrosales
fredyrosales
10,572 Points

this,props.score

HI! I'm really enjoying this React course as it seems to be a challenge. I'm fairly understanding everything as we progress. I just would like if someone can re iterate in words why we put the this. Is the this connected to the class itself?

2 Answers

Jesus Mendoza
Jesus Mendoza
23,289 Points

Hey,

If you notice; React.createClass takes an object as argument, so "this" will point to that object.

So, when you use your new class to create a new component and pass prop to that component class, "this" will points to that component(object) and this.props will point to that object propTypes.

I am sorry I am still having a hard time following. If this.props.score is not used, then what will props.score search for ?

Brice Roberts
Brice Roberts
22,415 Points

Dead issue, I know...

But, If any future students are looking into this question, take a look at this course if you're having trouble with "this".

https://teamtreehouse.com/library/understanding-this-in-javascript