propTYpes default props code example

Example 1: proptypes array of objects

MyComponent.propTypes = {
  items: PropTypes.arrayOf(
    PropTypes.shape({
      code: PropTypes.string,
      id: PropTypes.number,
    })
  ),
};

Example 2: 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 3: react propthpes or

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