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

89
Visualizações
React change DOM every X seconds

I'm trying to render some cards with different content every 10 seconds, I first fetch the data from the API and then render the first set of data on cards and what I want to do is change the cards content every 10 seconds

For the moment I'm using this:


    const [cards, setCards] = useState<[]>([])

    useEffect(() => {

     props.data.map( (data: any, i: any) => 

          setTimeout(() => {
            setCards(data)
          }, i * 10000)
     )

    }, [cards])

    return (
        <Wrapper>
            <h1>Hello World!</h1>
            <Hero img={bg} />
            <Cards cards={cards} />
        </Wrapper>
    )

That's currently not working, what can I do to make it work correctly ? My final result is every 10 seconds change the content (I will implement some animations too)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Solution

I just removed cards from my useEffect hook and used an empty array instead.. Working fine.

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