grungnet/src/contexts/MapStageContext.tsx
Mitchell McCaffrey e48d19a817 Typescript
2021-07-16 21:39:45 +10:00

18 lines
518 B
TypeScript

import React, { useContext } from "react";
import Konva from "konva";
export type MapStage = React.MutableRefObject<Konva.Stage | null>;
const MapStageContext = React.createContext<MapStage | undefined>(undefined);
export const MapStageProvider = MapStageContext.Provider;
export function useMapStage() {
const context = useContext(MapStageContext);
if (context === undefined) {
throw new Error("useMapStage must be used within a MapStageProvider");
}
return context;
}
export default MapStageContext;