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

86
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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