From 2229795879f537ddf771529e8c11b13a2012a337 Mon Sep 17 00:00:00 2001 From: Nathan Vieira Marcelino Date: Mon, 20 May 2024 20:43:13 -0300 Subject: [PATCH] fix(frontend): localStorage context --- frontend/src/context/storage/useStorage.tsx | 24 ++++----------------- frontend/src/providers/app.tsx | 23 +++++++++++--------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/frontend/src/context/storage/useStorage.tsx b/frontend/src/context/storage/useStorage.tsx index 131afcdd..fdc54edb 100644 --- a/frontend/src/context/storage/useStorage.tsx +++ b/frontend/src/context/storage/useStorage.tsx @@ -1,9 +1,5 @@ -import React, { - type ReactNode, - createContext, - useCallback, - useContext, -} from "react"; +import { createCustomContext } from "@utils/createCustomContext.function"; +import React, { type ReactNode, useCallback } from "react"; import { stringifyOrKepOriginal, tryParseJSON } from "./utils/parseJson"; @@ -14,20 +10,8 @@ interface IStorageContext { clear: () => void; } -const defaultStorageState = { - getItem: (_k: string) => null, - setItem: (_k: string, _v: string | object) => {}, - removeItem: (_k: string) => {}, - clear: () => {}, -}; - -const StorageContext = createContext(defaultStorageState); - -export function useStorage(): IStorageContext { - const context = useContext(StorageContext); - - return context; -} +export const [StorageContext, useStorage] = + createCustomContext("Storage Context"); export const StorageProvider: React.FC<{ children?: ReactNode }> = ({ children, diff --git a/frontend/src/providers/app.tsx b/frontend/src/providers/app.tsx index 3b3dc2e2..cca069e3 100644 --- a/frontend/src/providers/app.tsx +++ b/frontend/src/providers/app.tsx @@ -12,19 +12,22 @@ import "react-toastify/dist/ReactToastify.css"; import { AppRoutes } from "../routes"; export const App: FC = () => ( - - - - - + + + + + - - - - - + + + + + ); export default App;