React: isRequired is not working when having a default prop for that required property

453 views Asked by At

I have a field score which is required. I want to provide a default value for it as a fallback, so the warning will be displayed in console but the app will work as normal meanwhile.

Score.defaultProps = {
  dot  : false,
  score: 100
}

Score.propTypes = {
  score: PropTypes.number.isRequired,
  dot  : PropTypes.bool
}

If I remove the the default value, it works as expected.

I'm in Storybook and I need to display a table with PropTypes as follows:

expected output in Storybook

current output with default score

0

There are 0 answers