In my component, I want a props to be an enum as follows:
enum choices {
wide,
medium,
small
}
interface props {
size: choices
}
function SizeSelector({size}: props){
//...do stuff
}
then I want to do prop-types on it:
SizeSelector.propTypes = {
size: PropTypes.oneOf(choices) //doesn't work
}
How do I make it part of the PropTypes validation?
CodePudding user response:
Try this
SizeSelector.propTypes = {
size: PropTypes.oneOf(['wide', 'medium', 'small'])
}