Skip to content

Commit

Permalink
fix(sankey): include link's index in the React Component key when cre…
Browse files Browse the repository at this point in the history
…ating the SVG element (#2037)

* Include link's index in the react's key prop

This is to support custom color gradients for multiple links between the same two nodes. Also prevents the duplicate child key error when 2+ links attach to the same two nodes.

* Include Sankey link's index in the gradient id

Support custom color gradients for multiple links between the same two nodes.
  • Loading branch information
Ellis-808 authored Jun 17, 2022
1 parent b78c3d1 commit 5985ab4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/sankey/src/SankeyLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const SankeyLinks = <N extends DefaultNode, L extends DefaultLink>({
<>
{links.map(link => (
<SankeyLinksItem<N, L>
key={`${link.source.id}.${link.target.id}`}
key={`${link.source.id}.${link.target.id}.${link.index}`}
link={link}
layout={layout}
path={getLinkPath(link, linkContract)}
Expand Down
2 changes: 1 addition & 1 deletion packages/sankey/src/SankeyLinksItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const SankeyLinksItem = <N extends DefaultNode, L extends DefaultLink>({
isInteractive,
onClick,
}: SankeyLinksItemProps<N, L>) => {
const linkId = `${link.source.id}.${link.target.id}`
const linkId = `${link.source.id}.${link.target.id}.${link.index}`

const { animate, config: springConfig } = useMotionConfig()
const animatedPath = useAnimatedPath(path)
Expand Down

0 comments on commit 5985ab4

Please sign in to comment.