MyComponent.js
я есть компонент<Button>
.
Если компонент не имеетthis.props.children
Я хочу установить опоруariaLabel
какisRequired
иначе может быть необязательным. Как я могу это сделать?
ariaLabel
опора не требуется:
<Button>Add to bag</Button>
ariaLabel
реквизит должен быть обязательным:
<Button ariaLabel="Add to bag" icon={ favorite } />
еслиthis.props.children
а такжеthis.props.ariaLabel
пусто, выдает ошибку, говорящую, чтоthis.props.ariaLabel
является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 */
};
Спасибо