Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda