This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
setReadableFormat(getReadableFormat); | |
},[counterInSeconds]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
setCounterInSeconds(timeInSeconds); | |
},[timeInSeconds]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
if(counterInSeconds as number > 0 && startTimer){ | |
setTimeout(() => { | |
setCounterInSeconds(prevCount => prevCount as number - 1); | |
setReadableFormat(getReadableFormat); | |
}, 1000); | |
} | |
if(counterInSeconds === 0){ | |
endTimerFunc(); | |
setCounterInSeconds(timeInSeconds); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getReadableFormat = useMemo(() => { | |
let seconds : string | number = counterInSeconds as number % 60; | |
let minutes : string | number = Math.floor(counterInSeconds as number / 60); | |
minutes = minutes.toString().length === 1 ? "0" + minutes : minutes; | |
seconds = seconds.toString().length === 1 ? "0" + seconds : seconds; | |
return `${minutes} : ${seconds}`; | |
}, [counterInSeconds]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { FC, useEffect, useMemo, useState } from 'react' | |
interface TimerProps { | |
startTimer: boolean; | |
endTimerFunc: () => void; | |
timeInSeconds: number; | |
} | |
const Timer : FC<TimerProps> = ({ | |
startTimer, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{endTimer && displayResult()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [inputVal, setInputVal] = useState<string>(''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{inputVal.length > 0 && <button>Reset</button>} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [endTimer, setEndTimer] = useState<boolean>(false); | |
const [eligibleToStart, setElegibleToStart] = useState<boolean>(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{!endTimer && eligibleToStart && <InputBox/>} |