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

175
Vistas
requestAnimationFrame doesn't update repeatedly a react component

Just want to know why my requestAnimationFrame doesn't update my react component repeatedly? it only returned count value the very first time,and then it ignore it. here's the code :

// ----- animation.js
import React from "react";

let count = 0;
export default function Update() {
  return <>{UpdateComponents()}</>;
}

function UpdateComponents() {
  count++;

  window.requestAnimationFrame(UpdateComponents);

  return <p>count: {count}</p>;
}

// ------ index.js
// ReactDOM.render(<Update />, document.getElementById("root"));
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

export default function Update() {
  return <>{UpdateComponents()}</>;
}

<Update /> render what the first UpdateComponents() returned, but the return of the other UpdateComponents() invoked by window.requestAnimationFrame doesn't used by any Component, so requestAnimationFrame is working, but not impacts the content of the dom.

about 4 years ago · Juan Pablo Isaza Denunciar

0

requestAnimationFrame is working as you expect, if you add a console.log(count) after the place where you increment count you'll see the value changing.

The reason it isn't showing up in your DOM is that no component is tracking the value of count so nothing knows that it should be re-rendered. You'll need to hook your updates into state or prop changes in order to make the component show the 'live' count.

about 4 years ago · Juan Pablo Isaza Denunciar

0

It doesn't rerender because it doesn't trigger the reactdom In other for it to rerender repeatedly Use this piece of code

import React,{useState} from "react";


export default function Update() {
Let [count, setCount]=useState(0)
function UpdateComponents() {

  var newcount=count + 1;
setCount(newCount)
  window.requestAnimationFrame(UpdateComponents);
UpdateComponents()
 
}
  return <><p>count: {count}</p></>
}


This should work perfectly

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