diff --git a/src/react-cropper.tsx b/src/react-cropper.tsx index f0496527..8521adb1 100644 --- a/src/react-cropper.tsx +++ b/src/react-cropper.tsx @@ -100,6 +100,17 @@ const ReactCropper = React.forwardRef { + const currentRef: any = combinedRef.current; + if(currentRef && currentRef?.cropper?.canvasData && typeof props?.zoomTo === 'number') { + const cropper = currentRef.cropper; + cropper.zoomTo(props.zoomTo); + } + },[props.zoomTo]); + /** * re-render when src changes */ diff --git a/tests/react-cropper.test.tsx b/tests/react-cropper.test.tsx index 7d4a92c2..b820937a 100644 --- a/tests/react-cropper.test.tsx +++ b/tests/react-cropper.test.tsx @@ -55,6 +55,12 @@ describe('Cropper Render Tests', () => { rerender(); expect(ref.src).toEqual(newImage); }); + + test('renders cropper with zoomTo prop', async () => { + const onInitialized = jest.fn(); + render(); + await waitFor(() => expect(onInitialized).toHaveBeenCalledTimes(1)); + }); }); describe('Test Cropper Methods', () => {