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

133
Visualizações
Useeffect setstate missing dependency warning

I've got a question regarding a missing dependency warning.

I've got a GET request where I'd like to set the catch error state. However when setting the error it asks to add the setError in the dependency list. The dependency should only be the {value}, not the setError right?

useEffect(() => {
    if (value.length === 3) {
      setLoading(true);
      axios
        .get(
          `https://url.com?search=${value}`
        )
        .then((res) => setCompanies(res.data.data))
        .then(() => setLoading(false))
        .catch((err) => {
          if (err.response.status === 500) {
            setError("something went wrong");
          }
        });
    }
  }, [value]);

Warning notification: React Hook useEffect has a missing dependency: 'setError'. Either include it or remove the dependency array.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you need to declare setError() and error :

const [error,setError] = useState('');

useEffect(() => {
    if (value.length === 3) {
      setLoading(true);
      axios
        .get(
          `https://url.com?search=${value}`
        )
        .then((res) => setCompanies(res.data.data))
        .then(() => setLoading(false))
        .catch((err) => {
          if (err.response.status === 500) {
            setError("something went wrong");
          }
        });
    }
  }, [value]);
about 4 years ago · Santiago Trujillo 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