May 2017
Intermediate to advanced
388 pages
7h 30m
English
React comes with one very useful feature--PropTypes. PropTypes are a type checking mechanism on received props. It's a good practice to include these checks in every component. You can skip this part if you are using other tools, such as TypeScript or Facebook's Flow.
It works pretty well. For example, if we change the onAddToCart type from PropTypes.func to a PropTypes.string, it will throw an error. You can also add isRequired to each prop that can catch missing props that you may want to be necessary to the component.
This improves component reusability and readability, and it can also serve as a code documentation.
Read now
Unlock full access