Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda