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

189
Views
Best way to useEffect with multiple arguments passing in array

I am using useEffect in this way in my react component

  const [activePage, setActivePage] = useState(1);
  const [userId] = useState(localStorage.getItem("__uid"));
  const [dateRange, setDateRange] = useState([]);
  const [sort, setSort] = useState({ _id: -1 });
  const [count, setCount] = useState(0);
  const [type, setType] = useState("automate");
  const [search, setSearch] = useState("");


  useEffect(() => {
    allClips();
  }, [activePage, dateRange, userId, sort, type, searchText]);

So instead of passing each parameter as an argument I have done this

  useEffect(() => {
    allClips();
  }, [count]);

And changing the count on every of the state changes after setting above ones like this

   onChangeActivePage = (activePage) => {
     setActivePage(activePage)
     setCount(count + 1)
   } 

So is it a correct way or it could fail since the setState is async function?

about 4 years ago · Juan Pablo Isaza
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!