Skip to Content
You are viewing the v12 docs of React Flow. You can find the latest version here.
ReferenceHooks

useNodesInitialized()

Source on GitHub 

This hook tells you whether all the nodes in a flow have been measured and given a width and height. When you add a node to the flow, this hook will return false and then true again once the node has been measured.

import { useReactFlow, useNodesInitialized } from '@xyflow/react'; import { useEffect, useState } from 'react'; const options = { includeHiddenNodes: false, }; export default function useLayout() { const { getNodes } = useReactFlow(); const nodesInitialized = useNodesInitialized(options); const [layoutedNodes, setLayoutedNodes] = useState(getNodes()); useEffect(() => { if (nodesInitialized) { setLayoutedNodes(yourLayoutingFunction(getNodes())); } }, [nodesInitialized]); return layoutedNodes; }

Signature

Parameters:
NameTypeDefault
options.includeHiddenNodesbooleanfalse
Returns:
boolean

Notes

  • This hook always returns false if the internal nodes array is empty.
Last updated on