30 lines
733 B
TypeScript
30 lines
733 B
TypeScript
import { signal, Signal } from "@preact/signals";
|
|
import { createContext, JSX } from "preact";
|
|
import { useContext } from "preact/hooks";
|
|
|
|
interface AppContextValue {
|
|
isLoggedIn: Signal<boolean>;
|
|
}
|
|
|
|
const AppContext = createContext<AppContextValue>({
|
|
isLoggedIn: signal(false),
|
|
});
|
|
|
|
const AppProvider = ({ children }: { children: JSX.Element }) => {
|
|
const value: AppContextValue = {
|
|
isLoggedIn: signal(false),
|
|
};
|
|
|
|
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
|
|
};
|
|
|
|
const useAppContext = () => {
|
|
const context = useContext(AppContext);
|
|
if (!context) {
|
|
throw new Error("useAppContext must be used within AppProvider");
|
|
}
|
|
return context;
|
|
};
|
|
|
|
export { AppProvider, useAppContext };
|