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

160
Visualizações
How to maintain a cached data pool using react-query

I want to create a custom hook that maintains a cache and fetches only new items.

Expected behavior:

If I requested [1, 2, 3, 4, 5] initially, it fetches all [1, 2, 3, 4, 5] since the cache is empty.

If I requested [1, 2, 3] then, it shouldn't fetch anything and returns from the cache.

If I requested [4, 5, 6] then, it should take 4 and 5 from the cache and fetch only 6 and add that to the cache.

How can I achieve this optimistically?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you're already using react-query, then you don't need a custom hook: it already manages this cache for you based on your query keys:

At its core, React Query manages query caching for you based on query keys.

It also already provides a hook for parallel (concurrent), independent queries. That hook is called useQueries:

const results = useQueries({
  queries: [
    { queryKey: ['post', 1], queryFn: () => fetchPost(1) },
    { queryKey: ['post', 2], queryFn: () => fetchPost(2) },
  ],
});
about 4 years ago · Juan Pablo Isaza Relatório
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