grungnet/src/contexts/MapStageContext.tsx

18 lines
518 B
TypeScript
Raw Permalink Normal View History

import React, { useContext } from "react";
2021-07-16 07:39:45 -04:00
import Konva from "konva";
2020-05-21 02:46:50 -04:00
2021-07-16 07:39:45 -04:00
export type MapStage = React.MutableRefObject<Konva.Stage | null>;
2021-07-13 04:50:18 -04:00
const MapStageContext = React.createContext<MapStage | undefined>(undefined);
export const MapStageProvider = MapStageContext.Provider;
2020-05-21 02:46:50 -04:00
export function useMapStage() {
const context = useContext(MapStageContext);
if (context === undefined) {
throw new Error("useMapStage must be used within a MapStageProvider");
}
return context;
}
2020-05-21 02:46:50 -04:00
export default MapStageContext;