Skip to content

Commit 1d269f6

Browse files
dvoytenkohuozhi
andauthored
(fix) keepPreviousData: return fallback instead of undefined value (#4087)
Co-authored-by: Jiachi Liu <[email protected]>
1 parent 42c05f1 commit 1d269f6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/index/use-swr.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ export const useSWRHandler = <Data = any, Error = any>(
278278

279279
const returnedData = keepPreviousData
280280
? isUndefined(cachedData)
281-
? laggyDataRef.current ?? data
281+
// checking undefined to avoid null being fallback as well
282+
? isUndefined(laggyDataRef.current)
283+
? data
284+
: laggyDataRef.current
282285
: cachedData
283286
: data
284287

0 commit comments

Comments
 (0)