[英]How to add two Actions to a button In react.js
I have a problem in combine 2 action in the same button 我在同一个按钮中合并2个动作时遇到问题
<Button
disabled={!isFormValid}`
onClicked={this.submitHandler}
/>
I want to add this function with the previous one 我想在上一个添加此功能
() => this.popUpHandler('update');
The first action to submit form and next to close popup after that. 提交表单的第一个操作,然后关闭弹出窗口。 Do you have any idea about it?
你有什么想法吗?
Use Anonymous_functions . 使用Anonymous_functions 。
<Button
disabled={!isFormValid}
onClicked={ () => {
this.popupHandler("Update");
console.log('Button clicked');
}}
/>
Or create a separate handler; 或创建一个单独的处理程序;
Class Something extends React.Component {
onButtonClick() {
// Do anything
this.popupHandler("Update");
console.log('Button clicked');
}
render() {
return (
<Button
disabled={!isFormValid}
onClicked={this.onButtonClick()}
/>
);
}
}
You can simply use 您可以简单地使用
submitHandler(){
//after some condition you can call here another function
this.popUpHandler('update')
}
popUpHandler(var){
//your logic
}
<Button
disabled={!isFormValid}
onClicked={this.submitHandler}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.