feat(hooks): add useNodeDimensions

This commit is contained in:
moklick
2021-12-07 01:58:48 +01:00
parent 79a32ae2fc
commit 731918dc13
+31
View File
@@ -0,0 +1,31 @@
import { useCallback } from 'react';
import shallow from 'zustand/shallow';
import { Rect } from '../types';
import { useStore } from '../store';
function useNodeDimensions(id: string): Rect | null {
const nodeDimensions = useStore(
useCallback(
(s) => {
const nodeItem = s.nodeInternals.get(id);
if (!nodeItem) {
return null;
}
return {
...nodeItem.positionAbsolute,
width: nodeItem.width,
height: nodeItem.height,
};
},
[id]
),
shallow
);
return nodeDimensions;
}
export default useNodeDimensions;