How to build a custom timer hook in React.js? | useTimer | JavaScript Interview Question
@Yomesh Gupta

ReactAll Levels
2175
Do you see value in our efforts?

Devtools Tech is a free platform for Frontend Engineers. It takes a lot of time, effort, and finanical resources to keep the platform running. If you see any value in our work and would like to support us then you can do using the following options.

InternationalDomestic

Create a custom hook called useTimer that provides the following API

const TOTAL_TIME = 5;
const { isRunning, start, stop, seconds } = useTimer(TOTAL_TIME);
  • Show two buttons on the screen start & stop.
  • One button to start the timer. When the timer is running then show remaining seconds on the screen.
  • Another button to stop the timer. When the timer stops/reaches to 0 then it resets to total time and shows “No Timer Running” on the screen.

Video Demo:

Demo Link: https://d0uo7.csb.app/