Skip to content

Commit 3877e5a

Browse files
committed
Small clean-ups
1 parent 203d3eb commit 3877e5a

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/extensions/react-flow/nodes/NodeContent.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export function NodeContent<CONTENT_PROPS = any>({
359359

360360
const [width, setWidth] = React.useState<number | undefined>(nodeDimensions?.width ?? undefined);
361361
const [height, setHeight] = React.useState<number | undefined>(nodeDimensions?.height ?? undefined);
362-
// Keeps the inital size of the element
362+
// Keeps the initial size of the element
363363
const originalSize = React.useRef<NodeDimensions>({})
364364

365365
let zoom = 1;
@@ -398,9 +398,9 @@ export function NodeContent<CONTENT_PROPS = any>({
398398
if(nodeContentRef.current && !(originalSize.current.width || originalSize.current.height)) {
399399
saveOriginalSize();
400400
}
401-
}, [!!nodeContentRef.current, (!originalSize.current.width || !originalSize.current.height)])
401+
}, [!!nodeContentRef.current, !(originalSize.current.width || originalSize.current.height)])
402402

403-
// update node dimensions when resized
403+
// Update width and height when node dimensions parameters has changed
404404
React.useEffect(() => {
405405
const updateWidth = nodeDimensions?.width ? validateWidth(nodeDimensions?.width) : undefined;
406406
const updateHeight = nodeDimensions?.height ? validateHeight(nodeDimensions?.height) : undefined;
@@ -412,13 +412,11 @@ export function NodeContent<CONTENT_PROPS = any>({
412412
}
413413
}, [nodeDimensions]);
414414

415-
const isResizingActive = () : boolean => {
415+
const isResizingActive = React.useCallback((): boolean => {
416416
const currentClassNames = nodeContentRef.current.classList;
417-
const resizingActive =
418-
resizeDirections.right === currentClassNames.contains("is-resizable-horizontal") &&
417+
return resizeDirections.right === currentClassNames.contains("is-resizable-horizontal") &&
419418
resizeDirections.bottom === currentClassNames.contains("is-resizable-vertical");
420-
return resizingActive;
421-
}
419+
}, [])
422420

423421
// force default size when resizing is activated but no dimensions are set
424422
React.useEffect(() => {
@@ -432,7 +430,7 @@ export function NodeContent<CONTENT_PROPS = any>({
432430
setHeight(newHeight);
433431
}
434432
}
435-
}, [nodeContentRef.current, onNodeResize, minimalShape, resizeDirections?.bottom, resizeDirections?.right]); // need to be done everytime a property is changed and the element is re-rendered, otherwise the resizing class is lost
433+
}, [nodeContentRef.current, onNodeResize, minimalShape, resizeDirections?.bottom, resizeDirections?.right, width, height]); // need to be done everytime a property is changed and the element is re-rendered, otherwise the resizing class is lost
436434

437435
// conditional enhancements for activated resizing
438436
React.useEffect(() => {

0 commit comments

Comments
 (0)