useNodesInitialized
This hook returns true
when all nodes are initialized (measured by react flow and given a width and height). When you add a new node, it will return false
and then true
when the new node is initialized. It will always return false
when the nodes array is empty.
caution
This hook can only be used if the component that uses it is wrapped with a ReactFlowProvider
or if it's a child of the <ReactFlow />
component.
Usage
import { useEffect } from 'react';
import ReactFlow, { useNodesInitialized } from 'reactflow';
const options = {
includeHiddenNodes: false, // this is the default
};
function KeyLogger() {
const nodesInitialized = useNodesInitialized(options);
useEffect(() => {
if (nodesInitialized) {
// do some layouting
}
}, [nodesInitialized]);
return null;
}
Typescript
useNodesInitialized({ includeHiddenNodes }: UseNodesInitializedOptions): boolean