Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda