The following hooks can only be used if the component that uses it is a children of a
ReactFlowProvider
.
useZoomPanHelper
It can be used to modify the viewport of the react flow graph. Example:
import { useZoomPanHelper } from 'react-flow-renderer';
export default () => {
const { fitView } = useZoomPanHelper();
return (
<button
onClick={() => fitView({ padding: 0.2, includeHiddenNodes: true })}
></button>
);
};
The useZoomPanHelper
hook returns an object containing the following functions:
fitView = ({ padding: number, includeHiddenNodes: boolean }): void
- fits the view to the nodes on the pane. padding
is 0.1
and includeHiddenNodes
is false
by defaultzoomIn = (): void
- zooms inzoomOut = (): void
- zooms outzoomTo = (zoomLevel: number): void
- zooms to passed zoom leveltransform: (transform: FlowTransform): void
- sets the transform of the panesetCenter: (x: number, y: number, zoom?: number): void
- sets the center to the passed params. If no zoom is passed the maxZoom is usedfitBounds: (bounds: Rect, padding?: number): void
- fits the pane to the passed bounds (object with width x, y, width and height: { x: 0, y: 0, width: 100, height: 100 }
)project: (position: XYPosition) => XYPosition
: Transforms pixel coordinates to the internal ReactFlow coordinate system. This can be used when you drag nodes (from a side bar for example) and need the internal position on the pane.initialized: boolean
- true
when hook is initialized
useUpdateNodeInternals
When you are programatically changing the number or the position of handles inside a custom node you need to notify react flow about it with the useUpdateNodeInternals
hook. It also updates the internal size. Usage:
import { useUpdateNodeInternals } from 'react-flow-renderer';
export default () => {
const updateNodeInternals = useUpdateNodeInternals();
return <button onClick={() => updateNodeInternals('node-id')}></button>;
};