Skip to content

Commit

Permalink
fix: removed updated storagecontext.tsx Removed the unnecessary line …
Browse files Browse the repository at this point in the history
…localStorage.clear():
  • Loading branch information
AssahBismarkabah committed Mar 20, 2024
1 parent 9c1ec67 commit 089b27e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions power-pay-frontend/src/hooks/StorageContext.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createContext, PropsWithChildren, useEffect, useState } from 'react';

// Dethe StorageContextData interface.
// Define the StorageContextData interface.
export interface StorageContextData<T> {
item: Record<string, T>;
setItem: (key: string, value: T) => Promise<boolean>;
removeItem: (key: string) => Promise<boolean>;
clear: () => Promise<boolean>;
}

// Defining the StorageService interface.
// Define the StorageService interface.
interface StorageService {
getItem: <T>(key: string) => Promise<T | undefined>;
setItem: <T>(key: string, value: T) => Promise<boolean>;
Expand Down Expand Up @@ -61,12 +61,9 @@ export function StorageProvider<T>({ children, storageService }: PropsWithChildr
});
}, [storageService]);


// Updates the local storage whenever the state changes.
useEffect(() => {
if (storedValue !== undefined) {
storageService.setItem(STORAGE_KEY, storedValue);
}
storageService.setItem(STORAGE_KEY, storedValue);
}, [storageService, storedValue]);

// Remove the item from local storage and set the stored value to undefined
Expand All @@ -92,7 +89,6 @@ export function StorageProvider<T>({ children, storageService }: PropsWithChildr
},
removeItem: async (key) => clearItem(key),
clear: async () => {
localStorage.clear();
setStoredValue({});
return true;
},
Expand Down

0 comments on commit 089b27e

Please sign in to comment.