Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How to implement a delay timer that flip useState(true) to useState(false) in react js?

Im currently learning on tutorials of a project and they uses React Js for front end. This is my first time working on a react js so Im really confused on how to implement conditions of flipping:

'setShowAnimation' from true to false with a delay timer of 3 sec under the condition where 'setShowAnimation == true'. Any reference / guide is much appreciated!

const App = () => {
...
const [showAnimation, setShowAnimation] = useState(false);
...
   const wave = async () => {
     try {
   .......
     const waveTxn = await wavePortalContract.wave(tweetValue,{gasLimit:300000});
     console.log("Mining...", waveTxn.hash);

     setShowAnimation(true);
     .....
   }

React.useEffect(() => {
  const timeout = setTimeout(() => {
    setShowAnimation(false)
    },3000)
  return () => clearTimeout(timeout)
}, [showAnimation])

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you have to add a condition if it needs to be run only when showAnimation is true.

React.useEffect(() => {
    if(showAnimation){
       const timeout = setTimeout(() => {
          setShowAnimation(false)
       },3000)
       return () => clearTimeout(timeout)
     }
}, [showAnimation])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!