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 Components (2018) React Component Patterns Static PropTypes and Default Props

Seth M
seal-mask
.a{fill-rule:evenodd;}techdegree
Seth M
Web Development Techdegree Student 13,393 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,634 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!