mirror of
https://github.com/lumehq/lume.git
synced 2025-06-21 16:20:49 +02:00
18 lines
544 B
TypeScript
18 lines
544 B
TypeScript
import { PropsWithChildren, createContext, useContext, useMemo } from "react";
|
|
import { Ark } from "./ark";
|
|
|
|
export const ArkContext = createContext<Ark>(undefined);
|
|
|
|
export const ArkProvider = ({ children }: PropsWithChildren<object>) => {
|
|
const ark = useMemo(() => new Ark(), []);
|
|
return <ArkContext.Provider value={ark}>{children}</ArkContext.Provider>;
|
|
};
|
|
|
|
export const useArk = () => {
|
|
const context = useContext(ArkContext);
|
|
if (context === undefined) {
|
|
throw new Error("Ark Provider is not import");
|
|
}
|
|
return context;
|
|
};
|