Skip to content

Commit

Permalink
feat(transform-hook): UseTransformComponent added (#405)
Browse files Browse the repository at this point in the history
Hook added to return an element, given the current state

Co-authored-by: Tyler Lawson <tyler@secondspectrum.com>
  • Loading branch information
tylersayshi and Tyler Lawson authored Jun 20, 2024
1 parent e2b0df4 commit 042c283
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
16 changes: 16 additions & 0 deletions src/hooks/use-transform-component.tsx
Original file line number Diff line number Diff line change
@@ -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<T>(
callback: (state: ReactZoomPanPinchContextState) => T,
): T {
const libraryContext = useTransformContext();

return useMemo(
() => callback(getState(libraryContext)),
[libraryContext, callback],
);
}

0 comments on commit 042c283

Please sign in to comment.