Building a React.js App - ES6 Refactor: propTypes in ES6

Share this video with your friends

Send Tweet

In this video, we’ll refactor our Repos and UserProfile components and along the way we’ll learn how to utilize propTypes in React with JavaScript classes.

egghead eggo
egghead eggo
~ 9 years ago

The lesson video has been updated!

Cameron Roe
Cameron Roe
~ 9 years ago

You can also add the propTypes as a static property on the class using the babel-preset-stage-0. For example:

static propTypes = {
    username: React.PropTypes.string.isRequired,
    notes: React.PropTypes.array.isRequired,
    addNote: React.PropTypes.func.isRequired
};
Sergei
Sergei
~ 8 years ago

Why didn't we change the this references on the render methods to this.something().bind(this)? I thought that this didn't work using the class syntax when trying to reference things inside the Class from what you said on other videos.