Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Authentication Implementing Basic Authentication Implement the Sign up Form

How 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

We’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.