Skip to content

Commit

Permalink
(fix) keepPreviousData: return fallback instead of undefined value (#…
Browse files Browse the repository at this point in the history
…4087)

Co-authored-by: Jiachi Liu <[email protected]>
  • Loading branch information
dvoytenko and huozhi authored Feb 5, 2025
1 parent 42c05f1 commit 1d269f6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ export const useSWRHandler = <Data = any, Error = any>(

const returnedData = keepPreviousData
? isUndefined(cachedData)
? laggyDataRef.current ?? data
// checking undefined to avoid null being fallback as well
? isUndefined(laggyDataRef.current)
? data
: laggyDataRef.current
: cachedData
: data

Expand Down

0 comments on commit 1d269f6

Please sign in to comment.