proptypes react shape code example
Example 1: 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)
])
};
Example 2: proptypes shape
PropTypes.shape({ name: PropTypes.string, age: PropTypes.number })
Example 3: react propthpes or
size: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),