refactor src folder structure
This commit is contained in:
parent
0bfb70af8b
commit
d0e26e2882
30 changed files with 94 additions and 134 deletions
31
src/context/AppProvider.tsx
Normal file
31
src/context/AppProvider.tsx
Normal 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>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue