proptype array code example
Example 1: proptypes array of objects
MyComponent.propTypes = {
items: PropTypes.arrayOf(
PropTypes.shape({
code: PropTypes.string,
id: PropTypes.number,
})
),
};
Example 2: 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 3: react proptypes example
Detaljer.PropTypes = {
detaljer: PropTypes.string.isRequired,
feilkode: PropTypes.string,
removeEvent: PropTypes.string.isRequired
};
Detaljer.propTypes = {
detaljer: PropTypes.string.isRequired,
feilkode: PropTypes.string,
removeEvent: PropTypes.string.isRequired
};
Example 4: proptypes.arrayof/()
optionalArrayOf: PropTypes.arrayOf(PropTypes.number)
Example 5: react propthpes or
size: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),