``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
29 lines
806 B
TypeScript
29 lines
806 B
TypeScript
import React, { useContext, useMemo } from "react";
|
|
|
|
import { InventoryManager } from "@dndbeyond/character-rules-engine/es";
|
|
|
|
interface InventoryManagerContextValue {
|
|
inventoryManager: InventoryManager;
|
|
}
|
|
const initContext: InventoryManagerContextValue = {
|
|
inventoryManager: new InventoryManager(),
|
|
};
|
|
export const InventoryManagerContext =
|
|
React.createContext<InventoryManagerContextValue>(initContext);
|
|
|
|
export function InventoryManagerProvider({ children }) {
|
|
const inventoryManager: InventoryManager = useMemo(
|
|
() => new InventoryManager(),
|
|
[]
|
|
);
|
|
return (
|
|
<InventoryManagerContext.Provider value={{ inventoryManager }}>
|
|
{children}
|
|
</InventoryManagerContext.Provider>
|
|
);
|
|
}
|
|
|
|
export const useInventoryManager = () => {
|
|
return useContext(InventoryManagerContext);
|
|
};
|