Skip to content

useZoomCallbacks hook

A simple utility for ResumableZoom, CropZoom and Gallery components to handle common zoom events such as

Event NameDescription
onUpdateCallback triggered every time scale is updated
onStartCallback triggered the very fist time scale value changes
onEndCallback triggered once the scale value has returned to its base state
onMaxScaleReachedCallback triggered once the scale value is greater than equals the max scale value

How to use

useZoomCallbacks is dependant on the zoom component's current state, therefore you need to use useTransformState hook in order to get such values.

tsx
const {state, onUpdate} = useTransformationState("common")
useZoomCallbacks(
  state,
  {
    onUpdate: (scale) => console.log("Current scale value ", scale),
    onStart: () => console.log("Zoom started"),
    onEnd: () => console.log("Zoom finished"),
    onMaxScaleReached: (scale) => console.log("Reached max scale at", scale)
  }
)

<ResumableZoom onUpdate={onUpdate}>
  <Image />
</ResumableZoom>

Released under the MIT License.