最佳答案
如何发送 http 请求按钮点击与反应挂钩?或者,对于这个问题,如何做任何副作用按钮点击?
到目前为止,我所看到的是一些“间接”的东西,比如:
export default = () => {
const [sendRequest, setSendRequest] = useState(false);
useEffect(() => {
if(sendRequest){
//send the request
setSendRequest(false);
}
},
[sendRequest]);
return (
<input type="button" disabled={sendRequest} onClick={() => setSendRequest(true)}
);
}
这是正确的方式,还是有其他的模式?