After we define a class component, we get the value passed in from props, but we normally want the properties of the value passed in to be qualified, including whether it’s mandatory and what the default value is if it’s not. We can set it with the class name.propTypes = {} for example

Person.propTypes = {
  name: PropTypes.string.isRequired
}
Copy the code

This controls both type and mandatory, so how should the initial value be set?

Person.defaultProps = {
  name: 'Joe';
}
Copy the code

So, for component properties to be passed, the type and mandatory depend on the package propTypes, and the initial value is set according to defaultProps.

Note: Does this class name attribute look familiar? Remember when you could do that in Java? Is it static? That’s right. We can write these two things inside the class, using the static keyword. We said we can assign attributes to instances of classes directly, so we can also assign attributes to classes using the static keyword.

class Person extends React.Component {
  static propTypes = {
    name: PropTypes.string.isRequired
  }
  static defaultProps = {
    name: 'Joe'}}Copy the code