我使用react spring来设置svg路径的动画,切换strokeDashArray。这是我在母版中写的
const dashArrayAnimation = useSpring({
loop: {
reverse: true,
},
from: { strokeDasharray: toggle ? 0 : 5 },
to: { strokeDasharray: toggle ? 0 : 8 },
config: { duration: 500 },
});
并将这个常量传递给子组件,在子组件中,我试图定义其道具类型
interface Props {
type: Metric | undefined;
animationTracker: {
cardPositionName: string;
mouseOver: boolean;
trialType: number;
};
toggle: boolean;
setToggle: React.Dispatch<React.SetStateAction<boolean>>;
dashArrayAnimation: any;
}
它的道具类型是什么?
您应该从库中导入SpringValues
类型。然后,您可以传递一个与from/to
值相关的值对象,如下所示:
import { SpringValues } from '@react-spring/web'
interface Props {
type: Metric | undefined;
animationTracker: {
cardPositionName: string;
mouseOver: boolean;
trialType: number;
};
toggle: boolean;
setToggle: React.Dispatch<React.SetStateAction<boolean>>;
dashArrayAnimation: SpringValues<{ strokeDasharray: number }>;
}