[英]onClick not firing withing a SweetAlert modal in React.js
I'm using SweetAlert to take care of modals in my React.js application , and I have a functional component for the body of this particular modal.我正在使用SweetAlert来处理我的React.js 应用程序中的模式,并且我有一个用于这个特定模式的主体的功能组件。 It uses a simple state hook to increment/decrement the number value in between.
它使用一个简单的 state 挂钩来增加/减少两者之间的数值。 The issue is, that the onClick events are not firing at all.
问题是, onClick 事件根本没有触发。 I've tried debugging this in a number of ways, unsuccessfully.
我已经尝试以多种方式对此进行调试,但均未成功。 Any help is appreciated.
任何帮助表示赞赏。
export default class FoodItem extends React.Component{
constructor(props){
super(props);
this.state ={
loading:false,
addedPrice:0
}
this.openOptions = this.openOptions.bind(this);
}
componentDidMount(){
this.setState({
addedPrice:this.props.cena
});
}
openOptions(){
swal({
title:this.props.jedlo,
buttons:{
cancel:{
text:'Zrusit',
value:null,
visible:true,
closeModal:true
},
confirm:{
text:'Pridat ' + this.state.addedPrice,
value:true,
visible:true,
closeModal:true
}
},
content:(
<div>
<ModalBody />
</div>
)
});
}
render(){
return(
<button className='food-item' type="button" onClick={this.openOptions}>
<p className='food_text'>{this.props.jedlo}</p>
<p className='price_text'>{this.props.cena} €</p>
</button>
)
}
}
function ModalBody(){
const [num, changeNum] = useState(1);
return(
<div className='increaseNumItems'>
<button type='button' className='btnValueChange' onClick={() => changeNum(num - 1)}>-</button>
<p id='valueTimes'>{num}</p>
<button type='button' className='btnValueChange' onClick={() => changeNum(num + 1)}>+</button>
</div>
)
}
After hours of research, I've come to the conclusion that this particular sweetalert package is broken, I recommend using SweetAlert2 where everything seems to be working fine.经过数小时的研究,我得出的结论是,这个特别的 sweetalert package 坏了,我建议使用 SweetAlert2 一切似乎工作正常。
https://sweetalert2.github.io/ https://sweetalert2.github.io/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.