[英]How to submit react-form-hook programmatically?
我正在尝试向我的 react.js 项目添加一个 react-form-hook。 表格定义为:
<form onSubmit={handleSubmit(onSubmit)} ref={submitRef}>
//some input elements
<div className='d-flex justify-content-center' >
<button
type="submit"
className=" btn btn-warning" >
submit
</button>
</div>
</form>
onSubmit 方法定义为:
const onSubmit = data => {
console.log(data)
};
我正在尝试定义一个计时器(比如 10 分钟),并且我想在计时器到期后触发表单的 onSubmit 事件。 为此,我使用了 react-timer-hook,如下所示:
const time = new Date();
time.setSeconds(time.getSeconds() + 2);
let submitRef = useRef()
const {
seconds,
minutes,
hours,
days,
isRunning,
start,
pause,
resume,
restart,
} = useTimer({ time, onExpire: () => want to trigger the form submit event });
我应该如何定义 onExpire 属性?
formRef.current.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.