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

88
Views
Filter and data have missing dependency

I have one issue with my code where I need to filter though "id" and this is the error that I get " React Hook useEffect has missing dependencies: 'data' and 'filterData'. Either include them or remove the dependency array.



 useEffect(() => {
   if (content === "") {
     setFilterData(data); 
     return;
   }

   const filteredData = filterData.filter((item) => item.Id === content);
   setFilterData(filteredData);
 }, [content]);

 

 
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to add the dependency for data and filterData

  useEffect(() => {
   if (content === "") {
     setFilterData(data); 
     return;
   }

   const filteredData = filterData.filter((item) => item.Id === content);
   setFilterData(filteredData);
 }, [content, filterData, data]);

You can use the below code. This is the better implementation.

useEffect(() => {
  if(data){
   const filteredData = content === "" ? data : data.filter((item) => item.Id === content);
   setFilterData(filteredData);
   }
 }, [content, data]);

about 4 years ago · Juan Pablo Isaza Report

0

You only declared content as dependency in your useEffect block, but you're actually using data (which is a prop) and filterData (which is coming from useState()) as well.

These are dependencies and the error message is saying you need to declare them too (meaning your useEffect block will be executed every time one of its dependencies changes) or to remove depencencies at all (meaning your useEffect block will be executed only once):

 useEffect(() => {
       if (content === "") {
         setFilterData(data); 
         return;
       }
    
       const filteredData = filterData.filter((item) => item.Id === content);
       setFilterData(filteredData);
     }, 
     [content, data, filterData] // or [] for no depencencies
 );
about 4 years ago · Juan Pablo Isaza 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!