The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Building a React.js App: Component Validation with PropTypes

Building a React.js App: Component Validation with PropTypes

4:04
In this video, we’ll add PropTypes to some of our existing components to ensure that each component gets the data it needs to function properly.
Watch this lesson now
Avatar
egghead.io

In this video, we’ll add PropTypes to some of our existing components to ensure that each component gets the data it needs to function properly.

Avatar
Diego

Ok, now I know if PorpType is not set or if PropType is not the type that I just specified, but.., how can I validate if PropType value is undefined or if it has not value?, for example I expect a string, but I received an empty string, how can I handle that?

In reply to egghead.io
Avatar
Tyler

Hi Diego,

Check out the propTypes doc here (https://facebook.github.io/react/docs/reusable-components.html). You can do just about any sort of validation you want.

In reply to Diego
Avatar
egghead.io

The lesson video has been updated!

Avatar
cyberamigo

If anyone else is having the error:
"Uncaught TypeError: Cannot set property 'ReactFireMixin' of undefined"
make sure to double check the webpack.config.js that was my problem lol

Avatar
Shawy

For those who learning in ES6 syntax, I believe the propTypes setting would be, for example in UserProfile component, type these lines right after class UserProfile component :
UserProfile.propTypes = {
username: React.PropTypes.string.isRequired,
bio: React.PropTypes.object.isRequired
};
It works for me :)

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?