Back to Home

Proptypes

Published on

Best Practices React

proptypes

At the bottom of the component code, you are able to set the props you are expecting, and the type of those props, as well as if the are required or not. Etc.

Why? React props provide to you and additional collaborators what your component requires to work, and how the component is expecting. Without this, the programmer will have the read the entire component code to understand what types the props makes sense to be. And it’s pretty hard to track all of this. Especially when you have a huge amount of interconnected complex components.

It does not take long to do, and it provides so many benefits. It is like Typescript in a way. But absolutely desired. There is no harm in adding Proptypes too. There are React documentation libraries that are able to read PropTypes of a component and output that in its documentation, making it very easy to understand how to interface with a React Component API.

PropTypes I think are required for building robust components.