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

134
Vistas
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 Respuestas
Responde la pregunta

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