feat(hooks): useUpdateNodeInternals #916

This commit is contained in:
moklick
2021-03-01 16:52:38 +01:00
parent 5a36bf68ac
commit 3613c7c81d
6 changed files with 133 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { useCallback } from 'react';
import { useStoreActions } from '../store/hooks';
import { ElementId, UpdateNodeInternals } from '../types';
function useUpdateNodeInternals(): UpdateNodeInternals {
const updateNodeDimensions = useStoreActions((actions) => actions.updateNodeDimensions);
return useCallback<UpdateNodeInternals>((id: ElementId) => {
const nodeElement = document.querySelector(`.react-flow__node[data-id="${id}"]`);
if (nodeElement) {
updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]);
}
}, []);
}
export default useUpdateNodeInternals;