diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 054f4c9..7321a3b 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -2,3 +2,4 @@ export * from "./use-controls"; export * from "./use-transform-init"; export * from "./use-transform-effect"; export * from "./use-transform-context"; +export * from "./use-transform-component"; diff --git a/src/hooks/use-transform-component.tsx b/src/hooks/use-transform-component.tsx new file mode 100644 index 0000000..373e779 --- /dev/null +++ b/src/hooks/use-transform-component.tsx @@ -0,0 +1,16 @@ +import { useMemo } from "react"; + +import { useTransformContext } from "./use-transform-context"; +import { getState } from "utils"; +import { ReactZoomPanPinchContextState } from "../models"; + +export function useTransformComponent( + callback: (state: ReactZoomPanPinchContextState) => T, +): T { + const libraryContext = useTransformContext(); + + return useMemo( + () => callback(getState(libraryContext)), + [libraryContext, callback], + ); +}