[英]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.