Skip to content

Commit 6a403cd

Browse files
Small improvements
1 parent 2ed00fe commit 6a403cd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/x-charts/src/LineChart/AnimatedLine.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export interface AnimatedLineProps extends React.ComponentPropsWithoutRef<'path'
2020
}
2121

2222
const DURATION = 200;
23-
function useLineAnimatedProps(props: Pick<AnimatedLineProps, 'd' | 'skipAnimation'>) {
24-
const lastValues = React.useRef({ d: props.d });
23+
function useAnimatePath(props: Pick<AnimatedLineProps, 'd' | 'skipAnimation'>) {
24+
const lastDRef = React.useRef(props.d);
2525
const transitionRef = React.useRef<Transition<SVGPathElement, unknown, null, undefined>>(null);
2626
const [path, setPath] = React.useState<SVGPathElement | null>(null);
2727

@@ -31,7 +31,7 @@ function useLineAnimatedProps(props: Pick<AnimatedLineProps, 'd' | 'skipAnimatio
3131
return;
3232
}
3333

34-
const lastD = lastValues.current.d;
34+
const lastD = lastDRef.current;
3535
const stringInterpolator = interpolateString(lastD, props.d);
3636

3737
transitionRef.current = select(path)
@@ -40,7 +40,7 @@ function useLineAnimatedProps(props: Pick<AnimatedLineProps, 'd' | 'skipAnimatio
4040
.attrTween('d', () => (t) => {
4141
const interpolatedD = stringInterpolator(t);
4242

43-
lastValues.current = { d: interpolatedD };
43+
lastDRef.current = interpolatedD;
4444

4545
return interpolatedD;
4646
});
@@ -66,13 +66,14 @@ const AnimatedLine = React.forwardRef<SVGPathElement, AnimatedLineProps>(
6666
function AnimatedLine(props, ref) {
6767
const { d, skipAnimation, ownerState, ...other } = props;
6868

69-
const animateRef = useLineAnimatedProps(props);
69+
const animateRef = useAnimatePath(props);
7070
const forkRef = useForkRef(ref, animateRef);
7171

7272
return (
7373
<AppearingMask skipAnimation={skipAnimation} id={`${ownerState.id}-line-clip`}>
7474
<path
7575
ref={forkRef}
76+
// TODO: Removed `d` prop from the since `useAnimatePath` is handling it. Not sure how this impacts SSR, though.
7677
stroke={ownerState.gradientId ? `url(#${ownerState.gradientId})` : ownerState.color}
7778
strokeWidth={2}
7879
strokeLinejoin="round"

0 commit comments

Comments
 (0)