[英]How to detect if the form has been submitted?
我有反应的形式。
我需要检测表单是否已成功提交以在另一个表单中进行下一个请求
const formRef = React.useRef<HTMLFormElement>(null);
useEffect(() => {
if (formRef && formRef.current) {
formRef.current.submit();
}
}, [formRef]);
<>
<form
id="tdsMethodAcs"
method="post"
target="methodAcsFrame"
action={three_ds_method_url}
style={{ display: "none" }}
ref={formRef}
>
<input
type="hidden"
name="methodAcsFrame"
value={method_data_packed}
/>
<input type="submit" />
</form>
<iframe name="tdsMethodAcsFrame" width="0" height="0"></iframe>
</>
可能最短的方法是在提交表单时更改值的状态中创建一个变量。 有这样的想法:
const [formSubmitted, setFormSubmitted];
const onSubmit = () =>{
//Do stuff
setFormSubmitted(true);
}
useEffect(()=>{
//Do another stuff
},[formSubmitted])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.