refactor src folder structure

This commit is contained in:
Maarten 2024-08-13 09:22:08 +02:00
parent 0bfb70af8b
commit d0e26e2882
30 changed files with 94 additions and 134 deletions

View file

@ -0,0 +1,31 @@
import { createContext, PropsWithChildren, useContext } from "react";
import { useStorageState } from '@/src/context/UseStorageState';
type TokenType = {
token: string | null;
setToken: (token: string | null) => void;
isLoading: boolean;
}
const TokenContext = createContext<TokenType>( {
setToken: () => {
},
token: null,
isLoading: true,
} );
export const useToken = () => useContext( TokenContext );
export function AppProvider({ children }: PropsWithChildren) {
const [ [ isLoading, token ], setSession ] = useStorageState( 'appToken' );
const tokenContext: TokenType = {
token,
setToken: (token) => {
setSession( token );
},
isLoading,
};
return <TokenContext.Provider value={tokenContext}>{children}</TokenContext.Provider>;
}