feat: split contexts, providers and hooks

This commit is contained in:
Pihkaal
2024-05-30 15:55:59 +02:00
parent af5fc8cb35
commit 77f3b3ef40
13 changed files with 51 additions and 41 deletions

View File

@@ -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>
);
};

View File

@@ -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;