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 trial

JavaScript React Components (2018) React Component Patterns Static PropTypes and Default Props

Seth Missiaen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Seth Missiaen
Web Development Techdegree Graduate 21,652 Points

How can I target the value of the text input and define its PropType?

In the project files, Guil uses the following code in the AddPlayerForm component:

static propTypes = {
      addPlayer: PropTypes.func
};

It looks like the for this component, PropTypes only ensures that the addPlayer method called in the handleSubmit function is in fact a function.

Perhaps I'm misunderstanding the purpose of PropTypes, but can I use PropTypes to validate the text input by the user on the form for adding a player? Thanks so much!

1 Answer

Kevin D
Kevin D
8,646 Points

I don't think so! These types are only validated statically - which means that the errors will only be flagged in your code editor. If you want to provide some sort of validation on the front end for your user, you'll have to add that functionality in separately. These types help with the developer experience because it'll help catch any type errors for you before you compile your code!