countdown timer in seconds react

import React from 'react'
import { useState, useEffect } from 'react';

const Timer = (props:any) => {
    const {initialMinute = 0,initialSeconds = 0} = props;
    const [ minutes, setMinutes ] = useState(initialMinute);
    const [seconds, setSeconds ] =  useState(initialSeconds);
    useEffect(()=>{
    let myInterval = setInterval(() => {
            if (seconds > 0) {
                setSeconds(seconds - 1);
            }
            if (seconds === 0) {
                if (minutes === 0) {
                    clearInterval(myInterval)
                } else {
                    setMinutes(minutes - 1);
                    setSeconds(59);
                }
            } 
        }, 1000)
        return ()=> {
            clearInterval(myInterval);
          };
    });

    return (
        <div>
        { minutes === 0 && seconds === 0
            ? null
            : <h1> {minutes}:{seconds < 10 ?  `0${seconds}` : seconds}</h1> 
        }
        </div>
    )
}

export default Timer;

3.75
4
Rick9 120 points

                                    function App() {
  const [seconds, setSeconds] = React.useState(10);

  React.useEffect(() =&gt; {
    if (seconds &gt; 0) {
      setTimeout(() =&gt; setSeconds(seconds - 1), 1000);
    } else {
      setSeconds('BOOOOM!');
    }
  });

  return (
    &lt;div className=&quot;App&quot;&gt;
      &lt;div&gt;
        {seconds}
      &lt;/div&gt;
    &lt;/div&gt;
  );
}

3.75 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
countdown 5 seconds react js countdown timer 1 minute react react countdown number build a countdown timer using react react countdown time how to create a date countdown in react reactjs countdown using start date and time and end date and time using daynamic dates create countdown timer in reactjs countdown timer using reactjs react countdown days timer countdown react reactjs countdown timer hours minutes seconds react date using countdown timmer hour min days react date using countdown timmer react javascript timer countdown date time now 10 minutes react javascript timer countdown minutes seconds 2 minutes countdown timer react countdown react depending on date css countdown timer react reactjs countdown timer days minutes and second date countdown react how to set countdown react react component countdown with ago countdown timer in react with pause react date countdown react countdown timer with real time react display countdown timer react countdown timer from date seconds countdown timer react time countdown in react countdown to time in react countdown minutes react js class component countdown minutes react js react countdown timer hours, minutes seconds countdown time left react react seconds countdown countdown timer react functional component react js timer count up countdown clock react create a countdown in react 5 seconds countdown react how to do a countdown in react countdown 3 seconds in react react simple countdown timer animated countdown timer in react react timer minutes seconds 30 minute countdown timer react i am seeing countdown done on react state of timer minutes and seconds react react date/time countdown react countdown hours minutes how to make a countdown timer stop in react 10 minute countdown timer react how to create a countdown timer in react with minutes and seconds time countdown in react js create countdown in +react js countdown in +react js react show countdown react countdown timer stops countdown clock in website using react js react-countdown with days reactjs real time countdown timer react countdown timer example building a countdown with reactjs timer hours minutes and seconds in react react timer hours countdown react timer with hours minutes and secons countdown react timer with hours countdown how to make a countdown in react js make seconds countdown in react react timer countdown example reactjs timer countdown functional component countdown 15 second react js 5 seconds timer in reactjs make a countdown timer react react count down minutes timer countdown timer update with reactjs react countdown 30 second react countdown with end date second timer clock react countdown with react Countdown timer react js React component-countdown timer time used countdown react js CountDown app in React Js react-countdown how to display countdown for 1 hour time countdown react react js countdown timer component count down timer in react js timer countdown 30 seconds react timer count in react js how to run a countdown timer in react react countdown clock react countdown now react hour minute seconds countdown react time countdown create timer from end date react create countdown timer with date react template reactjs timer countdown react js time countdown to a timestamp react js time countdown seconds timer with react js start time count in seconds in react how to make timer counter in react js countdown seconds react react countdown timer to time react countdown timer line built in countdown in react react countdown timer bar react countdown timer input building a countdown timer in react countdown timer react that runs on a click of button count down clock on react count down timer in reactjs react seconds timer countdown timer count up reactjs react countdown timer by timestamp react timer countdown class component create countdown timer react building countdown timer in react js react-countdown restart countdown npm countdown timer react count down timer with hour minute second in react Creating a countdown timer in React countdown timer loading react countdown timer line react react countdown in hours and minutes countdown timer react hour / minute/ seconds 10 second countdown react countdown timer react reach 0 countdown timeer with stop button react countdown timer every second in react npm react time countdown react countdown component react javascript countdown timer countdown timer app react how to make a countdown timer react countdown of a seconds timer react components countdown of a number timer react components countdown of a number timer react countdown of a number react timer react class component countdown timer how to make countdown timer in react countdown start with button click react 30 second countdown timer react react countdown timer animation javascript countdown timer using react js react countdown timer minutes seconds how to start a countdown from a particular date in react js how to create a countdown timer in react how set a countdown in react.js react countdown tiemr react timer countdown for seconds react make a countdown how to make a countdown timer in react restart countdown timer react use countdown react timer seconds react countdown timer template react js react-countdown clock how to set a countdown to a particular datetime react react countdown timer npm how to make a 10 second countdown in react how to add a countdown in react simple countdown timer react react timer countdown class countdown day in react js react countdown to date implement countdown in react countdown in react 30 second countdown timer in react set timer for 10 seconds in reactjs inside return set timer for 10 seconds in reactjs countdown time react 60 seconds timer in react how to make count to zero after 1 min in react if count &gt;60 then display component in react based on time count show component in react react click counter timer javascript 3 second countdown react how to show countdown timer in react how to display a div with one minute time gap in react 1 minute of time gap in react js how to set react count down 60 sec 24 hrs time counter in react create timer in reactjs react countdown circle timer how can i change something in my page when countdown finish react timer react in show decremental timer reactjs show timer in from seconds reactjs react app that counts down from 10 how to countdown timer in react set count down timer reactjs how to add timer in react js react minute and second countdown timer react create timer creating a timer in react countdown js react HOOKS countdown js react react timer example countdown timer - npm react count down in react with state count down timer javascript reactjs countdown 5 minuites react make simple countdown react add timer to react dom create a timer in reactjs countdown component reactjs react js count down is it good to maintain timer in state in react class component timer react classs component timer seconds counter react 3 seconds counter react react native timer 1 min making a timer in react 59 seconds left in reactjs react counter timer timer code in react that decease every second class based timer code in react that decease every second set a timer react javascript timer countdown with seconds react codepen how to create counter timer in react js running timer in react timer with hours minutes and seconds in react 2 hour timer in reactjs create contdown react native class create seconds counter react native show count down in react how to create countdown timer in react js timer countdown in react react mobile timer add Cpunt down Timer in a button reactjs timer in recat timer countdown reactjs countdown timer reactjs 5mins counter in react react count down simple countdown react make countdown react make countdown timer on react how tp add timer to react js react js 24hour countdown timer decrease count in 1 second in react set timer react js react countdown simple timer in react countdown in react js count down timer in react how to make a count down in react how to create a time counter in react react 30 minutes timer countdown react component simple timer state react react 3 2 1 timer react countdowntimer simple count down clock react js react countdown timer codepen How to create the timer in react react free timer time without seconds in react react timer countdown and display clock time counter makes components render every time react react up and down counter time lapse How to implement count down react reactcountdown timer cooldown timer in react class based component cooldown timer in react timer app reacr how to add a countdown otp timer in react native na dmomenjs how to count seconds using time from js in react how to count seconds without setTimeout in react creater timer in react state react js timer how to make wuiz timer in react js time counter react react js countdown timer component sample react js timer component react js timer countdown create countdown timer in react how to create countdown timer in react.js react 10 second counter react js 10 second counter simple countdown with react react simple count down to show remaining time app countdown timer with react javascript timer react react count down timer by time of day hour minute second timer in react how to set a timer of 60 sec in react js React JS onClick Countdown timer 1 second counter react resend otp after 1 min react React JS one minute counter how to build a automatic time countdown in react show countodown react start countdown reactjs react native timer countdown for set amount of time timer app react react native count timer fetch timer for 10 minutes in react js seconds timer in react react count down timer how to make count down timer react react timer count up react div javascript with timer react countdown timer stackoverflow react counter time react countdown in ialog count down timer react create timer react js countdown react js how to create a chronometer in react reactjs timer for div reactjs timer example react countdown timer on click react native time counter not stop on 0 react countdown timer session countdown timer in reactjs reactjs countdown timer how to create react timer react class countdown timer 2 minute countdown timer react jsx display time left making a timer with react timer countdown class component react js making visible timer react creating a timer countdown react add countdown timer in react how to make time counter in react js timer react js count time reactjs timer days on two buttons react timer javascript code react display count down timer using react js react countdown timer without same value on rerender add timer to react.js how to set timer in react js time count in react how to set a live countdown on react how to make a timer in react secondstimer in react js show timer react reactjs timer automatic countdown timer react timer 5 minutes react native react decrement timer react native count seconds countdown react from 1 min react tutorial timer react native count elapsed time setinterval how to use timer in react js how to make a countdown in react react js countdown timer create timer react how to create timer in react how to build a countdown timer reactjs how to set a timer in react simple timer using react how to create a set timer in react countdown timer in react create ticker using reacrjs react count down seconds setting a resend timer in react js react create countdown timer countdown timer react native class react timer for 5 min countdown timer react timer for resend in react countdown timer example in react js create a countdown timer react prevent reactjs countdown in reactjs reactjs countdown time page timer reacr react count timer page timer react timer in react js count down in react class component how to countdown timer in react js using props how to countdown timer in react js how to create a count down timer in class based component in react how to create a count down timer in class based component make a timer in react js simple timer react application decrease the number in timer react js react clock ticking backwards countdown + react how to create countdown timer in react react seconds timer seconds ticker react countdown react how to make timer in react react timer component react countdown timer class setState react countdown timer class react timer class countdown javascript counting time react How to set a timer in reactjs live time counter react countdown button reactjs a countdown with setInterval in react otp countdown timer in react react reverse stopwatch countdown timer in react js countdowntimer in reactjs react js fetch get time left render time left in react js condown program react javascript countdown timer format react react timer class how to make a timed on react hour counter in react js time counter in react js simple react countdown react js call timer countdown create a timer in react how to create a timer react react countdown timer react seconds countdown seconds react countdown second component react countdown seconds count timer within a setinterval in reactjs count timer in reactjs react minute countdown react count down to 0 how to create a timer in react put timer in react app run a second timer in react js create a basic timer in react create countdown in reactjs setinterval countdown reactjs set count down reactjs react js countdown tempalte event startin counting minutes react react 10 second timer show timer in react js react timer react duration timer timer in react react create a second timer implement time in react timer on react time counter in react js stackoverflow timer in reactjs seconds minutes count up react react class timer timer react react timer app make a countdown website react react countdown continue on every render timer for quiz in react make timer in react countdown time with jsx react timer countdown seconds countdown react how to build a countdown timer with react how to build a countown timer with react building a countdown timer in react js reactjs class countdown timer examples reactjs countdown timer examples Building a Simple Countdown Timer With React countdown timer react 30 seconds 30 seconds timer react react countdown instead of change number react timere countdown timer in seconds react
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source