Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ArcherContainer/components/SvgArrows.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Property } from 'csstype';
import useUpdatableState from 'use-updatable-state';
import Vector2 from '../../geometry/Vector2';
import {
getPointCoordinatesFromAnchorPosition,
Expand All @@ -26,12 +27,12 @@ interface CommonProps {
cursor?: Property.Cursor;
}

const AdaptedArrow = (
const AdaptedArrow = React.memo(function AdaptedArrow(
props: Omit<SourceToTargetType, 'order'> &
CommonProps & {
parentCoordinates: Vector2;
},
) => {
) {
const style = props.style || {};
const newStartMarker = style.startMarker || props.startMarker;
const newEndMarker = style.endMarker ?? props.endMarker ?? true;
Expand Down Expand Up @@ -97,15 +98,18 @@ const AdaptedArrow = (
cursor={cursor}
/>
);
};
});

export const SvgArrows = (
props: {
parentCurrent: HTMLDivElement | null | undefined;
sourceToTargetsMap: Record<string, SourceToTargetsArrayType>;
} & CommonProps,
) => {
const parentCoordinates = getPointFromElement(props.parentCurrent);
const [parentCoordinates] = useUpdatableState(
getPointFromElement(props.parentCurrent),
(a, b) => a?.x === b?.x && a?.y === b?.y,
);

if (!parentCoordinates) {
// This happens when parent ref is not ready yet
Expand Down