refactor(useUpdateNodeInternals): make it easier to use #2008

This commit is contained in:
moklick
2022-08-16 12:58:33 +02:00
parent bb00e871c0
commit cb698975e4
3 changed files with 23 additions and 56 deletions
+2 -7
View File
@@ -10,15 +10,10 @@ function useUpdateNodeInternals(): UpdateNodeInternals {
const updateNodeDimensions = useStore(selector);
return useCallback<UpdateNodeInternals>((id: string) => {
const { domNode } = store.getState();
if (!domNode) {
return;
}
const nodeElement = domNode.querySelector(`.react-flow__node[data-id="${id}"]`) as HTMLDivElement;
const nodeElement = store.getState().domNode?.querySelector(`.react-flow__node[data-id="${id}"]`) as HTMLDivElement;
if (nodeElement) {
updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]);
requestAnimationFrame(() => updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]));
}
}, []);
}