bradxr
1/8/2019 - 12:26 PM

40 - Validating Props

  • better way of handling props, mostly if you write components that might be used by other developers
  • can restrict the types and values that you receive for your props
  • Person receives four important props: click, name, age, changed
  • there is an extra package that you can add for this
  • cmd npm install --save prop-types
  • provided by react team, allows us to check the type of our property
  • import statement: import PropTypes from 'prop-types';
  • used by going below the class definition
  • Person.propTypes = { click: PropTypes.func, name: PropTypes.string, age: PropTypes.number, changed: PropTypes.func };