Skip to content

Commit

Permalink
Handle cache update in test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mturley committed Aug 9, 2022
1 parent 2b8c764 commit 6e99595
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useLocalStorage/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const useLocalStorage = <T>(
? newValueOrFn(getValueFromStorage(key, defaultValue))
: newValueOrFn;
setValueInStorage(key, newValue);
if (typeof window === 'undefined') {
// If we're in a unit test environment, the cache won't update automatically since there's no StorageEvent.
setCachedValue(newValue);
}
},
[key, defaultValue]
);
Expand Down

0 comments on commit 6e99595

Please sign in to comment.