Merge pull request #2392 from wbkd/feat/useNodesInitialized
feat(hooks): add useNodesInitialized
This commit is contained in:
19
packages/core/src/hooks/useNodesInitialized.ts
Normal file
19
packages/core/src/hooks/useNodesInitialized.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ReactFlowState } from '../types';
|
||||
import { internalsSymbol } from '../utils';
|
||||
import { useStore } from './useStore';
|
||||
|
||||
const selector = (s: ReactFlowState) => {
|
||||
if (s.nodeInternals.size === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Array.from(s.nodeInternals.values()).every((n) => n[internalsSymbol]?.handleBounds !== undefined);
|
||||
};
|
||||
|
||||
function useNodesInitialized(): boolean {
|
||||
const initialized = useStore(selector);
|
||||
|
||||
return initialized;
|
||||
}
|
||||
|
||||
export default useNodesInitialized;
|
||||
@@ -41,5 +41,7 @@ export { default as useKeyPress } from './hooks/useKeyPress';
|
||||
export * from './hooks/useNodesEdgesState';
|
||||
export { useStore, useStoreApi } from './hooks/useStore';
|
||||
export { default as useOnViewportChange } from './hooks/useOnViewportChange';
|
||||
export { default as useOnSelectionChange } from './hooks/useOnSelectionChange';
|
||||
export { default as useNodesInitialized } from './hooks/useNodesInitialized';
|
||||
|
||||
export * from './types';
|
||||
|
||||
Reference in New Issue
Block a user