@zoom-image/react
Version:
Adapter of zoom image core for React
40 lines (38 loc) • 1.12 kB
JavaScript
import { noop } from './chunk-NURWQMNQ.mjs';
import { createZoomImageWheel } from '@zoom-image/core';
import { useRef, useState, useCallback, useEffect } from 'react';
function useZoomImageWheel() {
const result = useRef();
const [zoomImageState, updateZoomImageState] = useState({
currentZoom: 1,
enable: false,
currentPositionX: -1,
currentPositionY: -1,
currentRotation: 0
});
const createZoomImage = useCallback((...arg) => {
result.current?.cleanup();
result.current = createZoomImageWheel(...arg);
updateZoomImageState(result.current.getState());
result.current.subscribe(({ state }) => {
updateZoomImageState(state);
});
}, []);
const getZoomImageState = useCallback(() => {
return result.current?.getState();
}, []);
useEffect(() => {
return () => {
result.current?.cleanup();
};
}, []);
return {
createZoomImage,
zoomImageState,
getZoomImageState,
setZoomImageState: result.current?.setState ?? noop
};
}
export { useZoomImageWheel };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-MKWVBDA2.mjs.map