refactor(node-dimensions): use store domNode for calculation #2316

This commit is contained in:
moklick
2022-07-25 12:25:14 +02:00
parent 7a909e9425
commit 257588ce30
7 changed files with 73 additions and 53 deletions
+8 -2
View File
@@ -1,15 +1,21 @@
import { useCallback } from 'react';
import { useStore } from '../store';
import { useStore, useStoreApi } from '../store';
import { UpdateNodeInternals, ReactFlowState } from '../types';
const selector = (state: ReactFlowState) => state.updateNodeDimensions;
function useUpdateNodeInternals(): UpdateNodeInternals {
const store = useStoreApi();
const updateNodeDimensions = useStore(selector);
return useCallback<UpdateNodeInternals>((id: string) => {
const nodeElement = document.querySelector(`.react-flow__node[data-id="${id}"]`) as HTMLDivElement;
const { domNode } = store.getState();
if (!domNode) {
return;
}
const nodeElement = domNode.querySelector(`.react-flow__node[data-id="${id}"]`) as HTMLDivElement;
if (nodeElement) {
updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]);