static propTypes = {
// Value to display
value: PropTypes.string.isRequired,
// Wheter this values was chosen by user or not
isChosen: PropTypes.bool.isRequired,
// Gets called when user choses this value
onChoose: PropTypes.func.isRequired,
}
Why Should I add '.isRequired' in when defining the above PropTypes? I am a react-native beginer
If you define the PropType with isRequired
, React will warn you when you use that component without passing that prop.
// -> Warning: onChoose is required but not provided
<Component value={val} isChosen={true} />
If you do not define it, the property is considered optional and no warning is displayed if you don't pass the prop.
// -> No warnings, since the props are not required.
<Component />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With