Files
shanghai-residences/src/contexts/ScaleContext.tsx
T
2025-10-20 17:50:42 +08:00

32 lines
667 B
TypeScript

import { createContext, useContext, ReactNode } from "react";
export interface ScaleContextValue {
scale: number;
offsetX: number;
offsetY: number;
DESIGN_WIDTH: number;
DESIGN_HEIGHT: number;
}
const ScaleContext = createContext<ScaleContextValue | null>(null);
export function ScaleProvider({
children,
value,
}: {
children: ReactNode;
value: ScaleContextValue;
}) {
return (
<ScaleContext.Provider value={value}>{children}</ScaleContext.Provider>
);
}
export function useScale() {
const context = useContext(ScaleContext);
if (!context) {
throw new Error("useScale must be used within ScaleProvider");
}
return context;
}