[英]React JS. remove function from button after button is pressed
How to unmount.如何卸载。 Return does not work.退货不起作用。 I need to be able to press button and after function completes then the function will be remove from the button我需要能够按下按钮,在 function 完成后,function 将从按钮中移除
const handleSubmit = () => {
ipcRenderer.send(
"EDITOR",
[ type, typeValue],
"editor_response"
);
onClose(selectedValue);
};
return <div>
<Button onClick={handleSubmit} color="primary">
Ok
</Button>
</div>
Probably the cleanest solution is a state variable that determines whether the handler should be active or not.可能最干净的解决方案是 state 变量,它确定处理程序是否应该处于活动状态。
const MyComp = () => {
const [pressed, setPressed] = useState(false;
const handleSubmit = () => {
setPressed(true);
ipcRenderer.send(
"EDITOR",
[ type, typeValue],
"editor_response"
);
onClose(selectedValue);
};
const noop = () => {};
return <div>
<Button onClick={!pressed ? handleSubmit : noop} color="primary">
Ok
</Button>
</div>;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.