import { useListMachines } from "@/api/machine/machine"; import { MachinesResponse } from "@/api/model"; import { AxiosError, AxiosResponse } from "axios"; import React, { Dispatch, ReactNode, SetStateAction, createContext, useState, } from "react"; import { KeyedMutator } from "swr"; type AppContextType = { // data: AxiosResponse<{}, any> | undefined; data: AppState; isLoading: boolean; error: AxiosError | undefined; setAppState: Dispatch>; mutate: KeyedMutator>; swrKey: string | false | Record; }; // const initialState = { // isLoading: true, // } as const; export const AppContext = createContext({} as AppContextType); type AppState = { isJoined?: boolean; clanName?: string; }; interface AppContextProviderProps { children: ReactNode; } export const WithAppState = (props: AppContextProviderProps) => { const { children } = props; const { isLoading, error, mutate, swrKey } = useListMachines("defaultFlake"); const [data, setAppState] = useState({ isJoined: false }); return ( {children} ); }; export const useAppState = () => React.useContext(AppContext);