useOnViewportChange()
useOnViewportChange
钩子可让你监听视口的变化,例如平移和缩放。你可以为视口更改的每个阶段提供回调:onStart
、onChange
和 onEnd
。
¥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
Name | Type |
---|---|
#Params |
|
# options | object |
# options.onStart | (viewport: Viewport) => void |
# options.onChange | (viewport: Viewport) => void |
# options.onEnd | (viewport: Viewport) => void |
#Returns |
|
void |
注释
¥Notes
-
此钩子只能在作为
<ReactFlowProvider />
或<ReactFlow />
组件的子组件中使用。¥This hook can only be used in a component that is a child of a
<ReactFlowProvider />
or a<ReactFlow />
component.