Reference
useOnViewportChange()

useOnViewportChange

Source on GitHub (opens in a new tab)

The useOnViewportChange hook lets you listen for changes to the viewport such as panning and zooming. You can provide a callback for each phase of a viewport change: onStart, onChange, and onEnd.

import { useCallback } from 'react';
import { useOnViewportChange } from '@xyflow/react';
 
function ViewportChangeLogger() {
  useOnViewportChange({
    onStart: (viewport: Viewport) => console.log('start', viewport),
    onChange: (viewport: Viewport) => console.log('change', viewport),
    onEnd: (viewport: Viewport) => console.log('end', viewport),
  });
 
  return null;
}

Signature

#Params
#options
object
#options.onStart
(viewport: Viewport) => void
#options.onChange
(viewport: Viewport) => void
#options.onEnd
(viewport: Viewport) => void
#Returns
void

Notes