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

159
Views
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 answers
Answer question

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 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!