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

425
Vistas
useEffect cleanup function

I use the Usage Effect to implement cancellation. Accordingly, there is a delay, which is carried out in debounce. The use effect, as I understand it, makes the information leak and an empty function. How to make it so that if there is no "cost" State, then the function will not work and there will be no warning

Mistake:Warning: It is not possible to update the reaction state for the unmounted component. This is not an operation, but it indicates a memory leak in your application. To fix this, cancel all subscriptions and asynchronous tasks in the usage effect cleanup function.

Code:

    function useDebounce(value,fn, delay) {
      useEffect(() => {
          const handler = setTimeout(() => { fn() }, delay);
          return () => {  clearTimeout(handler) };
        },[value]);
    }

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can create a mounted check.

function useDebounce(value,fn, delay) {
  useEffect(() => {
    let mounted = true;
    const handler = setTimeout(() => {
       if (mounted) fn();
    }, delay);
    return () => {
      mounted = false;
      clearTimeout(handler);
    };
  },[value]);
}
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