7.26 Using PropTypes
Installation prop-types
Source: npmjs.com: Prop Types
- npm
- Yarn
npm install --save prop-types
yarn add prop-types
Usage prop-types
Person.js
import PropTypes from "prop-types";
...
Person.propTypes = {
click: PropTypes.func,
name: PropTypes.string,
age: PropTypes.number,
changed: PropTypes.func,
};
export default withClass(Person, classes.Person);
Feel free to use them on any component you have or on your most important components and definitely consider using them if you are building a component library which you want to share with other developers. So consider using them whenever you have scenarios where other people are using your components, and it might not be super clear which props your components take and which type of data goes into which prop.