Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

count down timer in react native

// isResendEnable is just my custom variable to check if i have enabled 
// resend function in my otp box
  const [timerCount, setTimer] = useState(20);
  const [activator, setActivator] = useState(Math.random());
  useEffect(() => {
    let interval;
    if (isResendEnable) {
      interval = setInterval(() => {
        if (timerCount > 0) {
          setTimer(lastTimerCount => {
            lastTimerCount <= 1 && clearInterval(interval);
            return lastTimerCount - 1;
          });
        }
      }, 1000);
    }

    return () => {
      if (isResendEnable) {
        clearInterval(interval);
      }
    };
  }, [activator]);
  
  return <Text> Resend in {timerCount} sec </Text>
Comment

react native countdown

import CountDown from 'react-native-countdown-component'; render() {    return (      <CountDown        size={30}        until={1000}        onFinish={() => alert('Finished')}        digitStyle={{backgroundColor: '#FFF', borderWidth: 2, borderColor: '#1CC625'}}        digitTxtStyle={{color: '#1CC625'}}        timeLabelStyle={{color: 'red', fontWeight: 'bold'}}        separatorStyle={{color: '#1CC625'}}        timeToShow={['H', 'M', 'S']}        timeLabels={{m: null, s: null}}        showSeparator      />    )}
Comment

PREVIOUS NEXT
Code Example
Javascript :: arrow functions basic usages in javascript 
Javascript :: convert json to csv npm 
Javascript :: regex capture group example 
Javascript :: how does square root work javascript 
Javascript :: javascript get date value from input 
Javascript :: javascript add to a dictionary 
Javascript :: inertia.js 
Javascript :: codesandbox react emet 
Javascript :: input variable in string javascript 
Javascript :: blur javascript 
Javascript :: react simple typewriter 
Javascript :: javascript practice questions 
Javascript :: JavaScript HTML DOM Events 
Javascript :: how to make a delete button in javascript 
Javascript :: how to run react code in visual studio 
Javascript :: how to remove an item from an object in javascript 
Javascript :: reach last array js 
Javascript :: show uploaded image in react/nextjs 
Javascript :: array example 
Javascript :: Javascript print/output 
Javascript :: hide react source 
Javascript :: default javascript 
Javascript :: JS longest word 
Javascript :: javascript remove last word from string 
Javascript :: add array type to sequelize migration 
Javascript :: chart js clear out chart 
Javascript :: math question 
Javascript :: convert excel date to javascript date 
Javascript :: unlimited number of arguments in function javascript 
Javascript :: can you get reinfected with the coronavirus 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =