Skip to content

Commit

Permalink
ximplify the modification
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Apr 24, 2024
1 parent 1fd1cac commit 17abb38
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions packages/x-charts/src/internals/useAnimatedPath.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import * as React from 'react';
import { interpolateString } from 'd3-interpolate';
import { useSpringRef, useSpring } from '@react-spring/web';
import { useSpring } from '@react-spring/web';

// Taken from Nivo
export const useAnimatedPath = (path: string, skipAnimation?: boolean) => {
const previousPathRef = React.useRef<string | null>(null);
const currentPathRef = React.useRef<string | null>(path);

const api = useSpringRef();

React.useEffect(() => {
if (previousPathRef.current !== path) {
// Only start the animation if the previouse path is different.
// Avoid re-animating if the props is updated with the same value.
api.start();
}

previousPathRef.current = currentPathRef.current;
currentPathRef.current = path;
}, [api, path]);
}, [path]);

const spring = useSpring({
ref: api,
from: { value: 0 },
to: { value: 1 },
reset: true,
Expand Down

0 comments on commit 17abb38

Please sign in to comment.