Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!