This is my Login.tsx
{!isVerify ? (
// Login form
) : (
<Verify data-phoneNumber={form.phoneNumber} data-countryCode={form.countryCode} />
)}
After send mobile with user, I change isVerify
to True
and <Verify />
component show to user.
And this is my verify:
const runTimer = () => {
useEffect(() => {
const interval = setInterval(() => {
console.log(time);
setTime(
(currentTime) => {
if (currentTime > 0) {
return currentTime - 1;
} else {
setResend(false)
clearInterval(interval);
return currentTime;
}
}
);
}, 1000);
return () => clearInterval(interval)
}, [])
}
const runAgain = () => {
runTimer()
}
return (
<div>
{runTimer()}
<div onClick={(e) => runAgain(e)}>Run Again</div>
</div>
)
For first time my timer work fine. but for second time not work! ( if I click on run again )