Skip to content

Instantly share code, notes, and snippets.

@ndudar
Created February 15, 2023 21:52
Show Gist options
  • Save ndudar/a5f2a318f5ab5f7e335b685c2017e5d8 to your computer and use it in GitHub Desktop.
Save ndudar/a5f2a318f5ab5f7e335b685c2017e5d8 to your computer and use it in GitHub Desktop.
Timer.js
//import the useTimer Hook from the appropriate file path
import { useTimer } from "./useTimer";
const Timer = (targetTimeMins) => {
//useTimer is invoked to get back the time remaining in minutes and seconds
const [minutes, seconds] = useTimer(targetTimeMins);
if (minutes + seconds <= 0) {
//if there is no time remaining, a component renders to say the time is up
return <ExpiredNotice />;
} else {
//otherwise the visual component of the timer is rendered, taking in the minutes and seconds as props
return <ShowTimer minutes={minutes} seconds={seconds} />;
}
};
export default Timer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment