File tree 2 files changed +8
-4
lines changed 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -475,7 +475,6 @@ function useSWR<Data = any, Error = any>(
475
475
return false
476
476
}
477
477
478
- cache . set ( key , newData )
479
478
cache . set ( keyErr , undefined )
480
479
cache . set ( keyValidating , false )
481
480
@@ -492,6 +491,7 @@ function useSWR<Data = any, Error = any>(
492
491
// deep compare to avoid extra re-render
493
492
// data changed
494
493
newState . data = newData
494
+ cache . set ( key , newData )
495
495
}
496
496
497
497
// merge the new state
Original file line number Diff line number Diff line change @@ -686,16 +686,17 @@ describe('useSWR - refresh', () => {
686
686
)
687
687
} )
688
688
689
- it ( 'should allow use custom isEqual method' , async ( ) => {
689
+ it ( 'should allow use custom compare method' , async ( ) => {
690
+ const key = 'dynamic-11'
690
691
function Page ( ) {
691
692
const { data, revalidate } = useSWR (
692
- 'dynamic-11' ,
693
+ key ,
693
694
( ) => ( {
694
695
timestamp : + new Date ( ) ,
695
696
version : '1.0'
696
697
} ) ,
697
698
{
698
- compare : function isEqual ( a , b ) {
699
+ compare : function compare ( a , b ) {
699
700
if ( a === b ) {
700
701
return true
701
702
}
@@ -724,6 +725,9 @@ describe('useSWR - refresh', () => {
724
725
return new Promise ( res => setTimeout ( res , 1 ) )
725
726
} )
726
727
const secondContent = container . firstChild . textContent
728
+ const cachedData = cache . get ( key )
729
+
730
+ expect ( cachedData . timestamp . toString ( ) ) . toEqual ( secondContent )
727
731
expect ( firstContent ) . toEqual ( secondContent )
728
732
} )
729
733
You can’t perform that action at this time.
0 commit comments