Move files to lib folder
This commit is contained in:
parent
d8d8ac35f8
commit
cec664c8d0
26 changed files with 58 additions and 59 deletions
31
lib/context/AppProvider.tsx
Normal file
31
lib/context/AppProvider.tsx
Normal file
|
@ -0,0 +1,31 @@
|
|||
import {createContext, PropsWithChildren, useContext} from "react";
|
||||
import {useStorageState} from '@/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