79405925

Date: 2025-02-02 01:00:56
Score: 1
Natty:
Report link

I want to share my solution for using conditional propTypes on a single prop value. Which is the case for showDropdown which and receive either bool || string.

const isBoolean = (val) => typeof val === 'boolean';
const isSring = (val) => typeof val === 'string' || val instanceof String;

Dropdown.propTypes = {
    data: PropTypes.array.isRequired,
    showDropdown: isRequiredIf(PropTypes.bool, props => (isBoolean(props.showDropdown) || isSring(props.showDropdown))),
    id: PropTypes.string.isRequired,
    classname: PropTypes.string,
}

NumaX hope this will help some fellow dev with the same doubt!!!

Reasons:
  • Whitelisted phrase (-1): hope this will help
  • RegEx Blacklisted phrase (1): I want
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: NumaX