22 lines
699 B
TypeScript
22 lines
699 B
TypeScript
import { createContext, type ReactNode, useContext } from "react";
|
|
import { useSidePanelState } from "../hooks/use-side-panel-state.js";
|
|
|
|
type SidePanelContextValue = ReturnType<typeof useSidePanelState>;
|
|
|
|
const SidePanelContext = createContext<SidePanelContextValue | null>(null);
|
|
|
|
export function SidePanelProvider({ children }: { children: ReactNode }) {
|
|
const value = useSidePanelState();
|
|
return (
|
|
<SidePanelContext.Provider value={value}>
|
|
{children}
|
|
</SidePanelContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useSidePanelContext(): SidePanelContextValue {
|
|
const ctx = useContext(SidePanelContext);
|
|
if (!ctx) throw new Error("useSidePanelContext requires SidePanelProvider");
|
|
return ctx;
|
|
}
|