I have the following React component:(我有以下React组件:)
<SweetAlert
show={this.props.message}
success
title={this.props.message}
onConfirm={this.props.handleCloseAlert}>
</SweetAlert>
And this is the alert I get with it:(这是我得到的警报:)
But I want the props success
to be dynamically chosen at execution time, so I tried this:(但是我希望在执行时动态选择道具success
,所以我尝试了以下方法:)
const alertType = () => {
switch(this.props.type) {
case ALERT_ERROR:
return 'error'
case ALERT_WARNING:
return 'warning'
case ALERT_DANGER:
return 'danger'
case ALERT_INFO:
return 'info'
case ALERT_SUCCESS:
return 'success'
}
}
<SweetAlert
show={this.props.message}
{...alertType()}
title={this.props.message}
onConfirm={this.props.handleCloseAlert}>
</SweetAlert>
But I loose the alert type with it:(但是我用它松开了警报类型:)
I haven't found a way for adding a discretional props to a component.(我还没有找到一种向组件中添加任意道具的方法。)
ask by HuLu ViCa translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…