Skip to content

Commit

Permalink
fix(frontend): localStorage context
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Vieira Marcelino committed May 20, 2024
1 parent 98d2fa6 commit 2229795
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
24 changes: 4 additions & 20 deletions frontend/src/context/storage/useStorage.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<IStorageContext>(defaultStorageState);

export function useStorage(): IStorageContext {
const context = useContext(StorageContext);

return context;
}
export const [StorageContext, useStorage] =
createCustomContext<IStorageContext>("Storage Context");

export const StorageProvider: React.FC<{ children?: ReactNode }> = ({
children,
Expand Down
23 changes: 13 additions & 10 deletions frontend/src/providers/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import "react-toastify/dist/ReactToastify.css";
import { AppRoutes } from "../routes";

export const App: FC = () => (
<ColorModeProvider>
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-right" />
<BrowserRouter>
<StorageProvider>
<StorageProvider>
<ColorModeProvider>
<QueryClientProvider client={queryClient}>
<ReactQueryDevtools
initialIsOpen={false}
buttonPosition="bottom-right"
/>
<BrowserRouter>
<AuthenticationProvider>
<AppRoutes />
</AuthenticationProvider>
</StorageProvider>
</BrowserRouter>
</QueryClientProvider>
<ToastContainer />
</ColorModeProvider>
</BrowserRouter>
</QueryClientProvider>
<ToastContainer />
</ColorModeProvider>
</StorageProvider>
);

export default App;

0 comments on commit 2229795

Please sign in to comment.