I have a component <Button>
.
If the component doesn't has this.props.children
, I want to set the prop ariaLabel
as isRequired
, otherwise in can be optional. How do I do that?
ariaLabel
prop not required:
<Button>Add to bag</Button>
ariaLabel
prop has to be required:
<Button ariaLabel="Add to bag" icon={ favorite } />
if this.props.children
and this.props.ariaLabel
are empty, it throws an error saying that this.props.ariaLabel
is isRequired
<Button icon={ favorite } />
propTypes:
Button.propTypes = {
/** icon inside Button. */
icon: React.PropTypes.object,
/** Content inside button */
children: React.PropTypes.node,
/** Aria-label to screen readers */
ariaLabel: React.PropTypes.string, /*isRequired if children is empty */
};
Thanks