array proptypes code example
Example 1: how to make proptypes either or
size: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
Example 2: proptypes array of objects
MyComponent.propTypes = {
items: PropTypes.arrayOf(
PropTypes.shape({
code: PropTypes.string,
id: PropTypes.number,
})
),
};
Example 3: proptypes oneof
import PropTypes from 'prop-types';
MyComponent.propTypes = {
optionalArray: PropTypes.array,
optionalBool: PropTypes.bool,
optionalFunc: PropTypes.func,
optionalNumber: PropTypes.number,
optionalObject: PropTypes.object,
optionalString: PropTypes.string,
optionalSymbol: PropTypes.symbol,
optionalUnion: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.instanceOf(Message)
])
};