Skip to content

Commit

Permalink
fix: don't deduplicate failed fetches
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 16, 2020
1 parent 4a1ad84 commit 1d0c78b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ export function useCache<T, K = null>(
function fetch(query = unwrap(key), force?: boolean) {
if (
!force &&
cache[query] &&
cache[query][1] !== 'error' &&
(cache[query][0] !== initialValue ||
cache[query][4] instanceof Promise) &&
deduplicate &&
(deduplicate === true ||
deduplicate < new Date().getTime() - cache[query]?.[2])
deduplicate < new Date().getTime() - cache[query][2])
)
return cache[query][4] instanceof Promise
? (cache[query][4] as Promise<T>)
Expand Down

0 comments on commit 1d0c78b

Please sign in to comment.