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 trialfairest
Full Stack JavaScript Techdegree Graduate 19,303 PointsHow does the userSignUp access props?
I thought alternative class syntax in React blocked the access to props? So, how does the userSignUp access props?
1 Answer
fairest
Full Stack JavaScript Techdegree Graduate 19,303 PointsWe’ve all been taught that the constructor is where we initialize our instance properties, state in this case. And if you are saying to yourself, “Exactly!”, then you would be absolutely correct… if not for the upcoming ES.next class properties proposal, currently in stage 3. With it we can now define class properties directly, like this.
class Foo extends Component {
state = { loading: true };
...
}
Babel will transpile your code and add a constructor for you behind the scenes. Here is the output from Babel when we transpile the code snippet above.
Note that Babel is actually passing all args — not just props — down to super. It is also taking super’s return value and passing it back to the caller. Both may be a bit overkill, but exactly what it should be doing.
Source: The constructor is dead, long live the constructor!
@ Guil Hernandez : might be helpful to include a little note on this in the React Authentication course.