I'm trying to add a react-hook-form to my react.js project. The form is defined as:
<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>
The onSubmit method is defined as:
const onSubmit = data => {
console.log(data)
};
I'm trying to define a timer (say 10 mins) and I want to trigger the onSubmit event of the form once the timer is expired. For this I used the react-timer-hook as follows:
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 });
How should I define the onExpire property?
handleSubmit(async (data) => await fetchAPI(data))
does not work. Thanks. – Hunger