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

85
Vistas
React Hook useEffect has a missing dependendency

I am developing a react JS website to assist TFserving

in my file home.js there is an error in the following line

  useEffect(() => {
    if (!preview) {
      return;
    }
    setIsloading(true);
    sendFile();
  }, [preview]);

Error message:-

React Hook useEffect has a missing dependency: 'sendFile'. Either include it or remove the dependency array.
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It is showing you the warning because you are using sendFile() method and you didn't add it to the dependency array. So you have two options.

1.) Add it to the dependency array

 useEffect(() => {
    if (!preview) {
      return;
    }
    setIsloading(true);
    sendFile();
  }, [preview, sendFile]);

2.) use eslint-disable-next-line By using this, It won't show the warning anymore.

  useEffect(() => {
    if (!preview) {
      return;
    }
    setIsloading(true);
    sendFile();
    //eslint-disable-next-line
  }, [preview]);
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want the effect to run only when preview changes then it is technically correct to specify just preview to dependency array. But, the React-hooks linting rules aren't able to differentiate this case. You can disable the rule specifically for that line with:

// eslint-disable-next-line react-hooks/exhaustive-deps

but better is using useCallback:

const sendFile= useCallback(() => {
  
}, [])

here, if you have dependencies in your function, you will have to include them in the useCallback dependencies array and this will trigger the useEffect again if the functions parameters changes.

about 4 years ago · Juan Pablo Isaza Denunciar

0

  useEffect(() => {
    if (!preview) {
      return;
    }
    setIsloading(true);
    sendFile();
  }, `[preview, setIsloading, sendFile]`);

You forgot to include functions that are used in the useEffect hook have to be in the dependency array since they are used from outside the hook. setState functions don't change reference over time so it won't change the behavior of the useEffect hook

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