Skip to content

Commit

Permalink
๐Ÿ›Fix: reset timer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethen1264 committed Dec 17, 2024
1 parent 87710e3 commit 468c1fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/entities/signUp/model/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { useEffect } from 'react';
export const useTimer = (
timer: number,
setTimer: React.Dispatch<React.SetStateAction<number>>,
setIsSmsSent: React.Dispatch<React.SetStateAction<boolean>>, // ์ถ”๊ฐ€
) => {
useEffect(() => {
if (timer > 0) {
const intervalId = setInterval(() => {
setTimer((prev) => prev - 1);
}, 1000);

return () => clearInterval(intervalId);
} else if (timer === 0) {
setIsSmsSent(false);
}
}, [timer, setTimer]);
}, [timer, setTimer, setIsSmsSent]);
};
2 changes: 1 addition & 1 deletion src/entities/signUp/ui/SignUpForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SignUpForm = () => {
watch('code'),
);

useTimer(timer, setTimer);
useTimer(timer, setTimer, setIsSmsSent);

return (
<form
Expand Down

0 comments on commit 468c1fe

Please sign in to comment.