feat: split contexts, providers and hooks
This commit is contained in:
@@ -1,22 +1,5 @@
|
||||
import { type ReactNode, createContext, useContext, useState } from "react";
|
||||
import { createContext } from "react";
|
||||
|
||||
export const AppContext = createContext<
|
||||
{ activeKitty: string; setActiveKitty: (value: string) => void } | undefined
|
||||
>(undefined);
|
||||
|
||||
export const useApp = () => {
|
||||
const app = useContext(AppContext);
|
||||
if (!app) throw new Error("`useApp` used outside AppContext");
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
export const AppProvider = (props: { children?: ReactNode }) => {
|
||||
const [activeKitty, setActiveKitty] = useState(":r0:");
|
||||
|
||||
return (
|
||||
<AppContext.Provider value={{ activeKitty, setActiveKitty }}>
|
||||
{props.children}
|
||||
</AppContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { createContext } from "react";
|
||||
|
||||
export const KittyContext = createContext<KittyContextProps | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
export const useKitty = () => useContext(KittyContext);
|
||||
|
||||
export type KittyContextProps = {
|
||||
rows: number;
|
||||
cols: number;
|
||||
|
||||
Reference in New Issue
Block a user