0
Hours
0
Minutes
0
Seconds
You need Login/Signup to run/submit the code.

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

@Yomesh Gupta
3495

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/