Skip to content

Commit

Permalink
fix undefined window errors
Browse files Browse the repository at this point in the history
  • Loading branch information
murageh committed Feb 22, 2023
1 parent 1b4c512 commit a687591
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hooks/saveProgress/useSaveProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ const useSaveProgress = ({key, initialValues, storage}: { key: string, initialVa

// Helper function to save the data to local storage
const saveValues = (value: any) => {
(storage ?? localStorage).setItem(key, JSON.stringify(value));
if (typeof window !== 'undefined') {
(storage ?? window.localStorage).setItem(key, JSON.stringify(value));
}
};

// Provide helper function to clear the data from local storage
const clearValues = () => {
setValues(initialValues || {});
(storage ?? localStorage).removeItem(key);
if (typeof window !== 'undefined') {
(storage ?? window.localStorage).removeItem(key);
}
};

// Provide helper function to update the data in local storage
Expand Down

0 comments on commit a687591

Please sign in to comment.