proptypes in class component code example

Example 1: how to make proptypes either or

size: PropTypes.oneOfType([
  PropTypes.string,
  PropTypes.number
]),

Example 2: how to make proptypes either or

size: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.oneOf([ 'SMALL', 'LARGE' ]),
]),

Example 3: prop-types

npm install --save prop-types

Example 4: react proptypes example

// proptypes using class component
Detaljer.PropTypes = {
  detaljer: PropTypes.string.isRequired,
  feilkode: PropTypes.string,
  removeEvent: PropTypes.string.isRequired
};

// proptypes using function component
Detaljer.propTypes = {
  detaljer: PropTypes.string.isRequired,
  feilkode: PropTypes.string,
  removeEvent: PropTypes.string.isRequired
};

Example 5: proptypes.objectof

Pokemon.propTypes = {
  pokemon: PropTypes.shape({
    name: PropTypes.string,
    id: PropTypes.number,
    base_stamina: PropTypes.number,
    base_defense: PropTypes.number
  })
}