我正在尝试将react-hook-form添加到我的react.js项目中。形式定义为:
<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属性?
2条答案
按热度按时间kse8i1jr1#
kupeojn62#
您可以手动调用
handleSubmit
从docs
类似的东西(未经测试)