t2-model-skinner/src/useImageLoader.ts
2022-12-02 22:26:17 -08:00

17 lines
484 B
TypeScript

import React, { useContext } from "react";
interface ImageLoaderContextValue {
loadImage: (url: string) => Promise<ArrayBuffer>;
}
export const ImageLoaderContext =
React.createContext<ImageLoaderContextValue | null>(null);
ImageLoaderContext.displayName = "ImageLoaderContext";
export default function useImageLoader() {
const context = useContext(ImageLoaderContext);
if (!context) {
throw new Error("ImageLoaderContext.Provider not found!");
}
return context;
}