Skip to content

aarondancer/react-isrequiredif

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

react-isrequiredif

Conditionally require a prop based on other props

Example:

SuperHero.propTypes = {
  title: PropTypes.string.isRequired,
  details: PropTypes.string,
  button: PropTypes.string,
  url: PropTypes.string,
  secondButton: PropTypes.string,
  secondAction: (...args) => isRequiredIf(
    ...args, ['secondButton'], ['string', 'func']
  )
}

Docs:

isRequiredIf(...args, requiredProps, type)

  • requiredProps is an array of prop names or a string of a single prop name. If a requiredProp has a value and the prop does not, it will return an error.

  • type is an array of PropTypes or a string of a single PropType. This works functionally the same as React.PropTypes.oneOfType.

About

Conditionally require a prop based on other props

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages