1. 8
    Validate Custom React Component Props with PropTypes
    4m 14s

Validate Custom React Component Props with PropTypes

Kent C. Dodds
InstructorKent C. Dodds

Share this video with your friends

Send Tweet

When you create reusable React components, you want to make sure that people use them correctly. The best way to do this is to use TypeScript in your codebase to give you compile-time checking of your code. But if you’re not using TypeScript, you can still use PropTypes to get runtime validation. Between you and me, when I was still doing AngularJS work, I was so envious of this feature, that I tried to build it into AngularJS.

In this lesson we’ll learn how PropTypes work, why they’re not enabled in production, and how to use the pre-built prop-types package from the React team.

Michael
Michael
~ a year ago

Officially it seems that PropTypes are not recommended ? With flow or typescript instead recommended.

https://reactjs.org/docs/static-type-checking.html

Ian Jones
Ian Jones
~ a year ago

For larger code bases

I think TS and Flow are great but it adds a whole other layer of complexity so it's nice to have an option the check props without all that config.