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 trialUla Troc
1,881 PointsWhat does Component instance mean?
When you create a class component that extends from React.Component, any custom methods you create are not bound to the component by default. You need to bind your custom methods, so that this refers to the component instance. In this video, we'll go over the ways to bind the this context in React.
3 Answers
joelearner
54,915 PointsHi Ula,
This sounds like OOP(object oriented programming). The teacher is saying that React.Component is a class. You have the ability in OOP to create your own definitions without impacting the original class, which is called creating an instance of the class.
Here, the teacher is saying that he will create a component variable based on the original class. Does this make sense?
Cheers!
Ezra Siton
12,644 PointsReact.Component
is a "build-in" class (With methods, Properties).
https://reactjs.org/docs/react-component.html
For example one "build-in" method of React.Component
is render()
.
In our code, we extend (==> Create child of another class) from React.Component
. Like this, we can use render()
or constructor()
without creating this methods inside our class + Add our own methods (Like "incramentsScore").
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends
This is not so simple Concept (You should learn a little about OOP).
The most basic example:
All birds class have a walk
method (And properties like "name" of "weight").
Flying-birds extends
"birds class" and add the "flying" method (Under `Flying-Birds" class you won't get an error if you run "walk" function =========> Same idea for the relationship between "Counter" class and "React.Component" class).
Vullli Venkateshwarlu
Courses Plus Student 187 Pointsi think React.Component is a function constructor