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

172
Views
Optimal way to refetch data when URL parameters change?

I have stumbled upon this problem a few times now. I need a way for the component to be able to track changes in the URL params and refetch data depending on it. For example, when the user searches "q=searchTerm" is applied. When paginating, "page=pageNumber" is applied and so on. It is easy to implement with just one parameter in a useEffect but when I have multiple such as search, sort, sort direction my knowledge of this is limited.

The code right now sort of works but if you are on say page 3 in pagination and then you search both effects get triggered because I want the pagination to go back to 1 after searching. It is not ideal.

I can't really find any good articles which deal with a more advanced version as they usually just demo the concept.

Can anyone recommend a good approach of dealing with multiple search parameters and how to efficiently update data?

    fetchMore({
      variables: {
        input: {
          offset: getOffset(MAX_PRODUCT_REVIEW_LIMIT, activePage),
          limit: MAX_PRODUCT_REVIEW_LIMIT,
          q: debouncedSearchTerm,
        },
      },
    });
  }, [activePage, fetchMore, debouncedSearchTerm]);

  useEffect(() => {
    Router.replace({
      query: {
        ...Router.query,
        q: debouncedSearchTerm,
        page: 1,
      },
    });
  }, [debouncedSearchTerm]);
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!