Skip to content

Commit a907103

Browse files
authored
Merge pull request #2334 from FormidableLabs/use-animation-state-fix
Fix for #2329 (use-animation-state crashing charts)
2 parents f4beada + 654dc7c commit a907103

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/victory-chart/src/victory-chart.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import { VictoryChart } from "victory-chart";
33
import { VictoryAxis } from "victory-axis";
4+
import { VictoryLine } from "victory";
45
import { render, screen, fireEvent } from "@testing-library/react";
56

67
describe("components/victory-chart", () => {
@@ -98,4 +99,16 @@ describe("components/victory-chart", () => {
9899
expect(clickHandler).toHaveBeenCalled();
99100
});
100101
});
102+
103+
describe("animation", () => {
104+
it("handles basic animation parameters without crashing", () => {
105+
const { container } = render(
106+
<VictoryChart animate={{ duration: 2000, easing: "bounce" }}>
107+
<VictoryLine />
108+
</VictoryChart>,
109+
);
110+
111+
expect(container.querySelector("svg")).toBeTruthy();
112+
});
113+
});
101114
});

packages/victory-core/src/victory-util/hooks/use-animation-state.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
2424
// This is a copy of Wrapper.getAnimationProps
2525
const getAnimationProps = React.useCallback(
2626
(props, child, index) => {
27-
if (!props.animate) {
27+
if (!props?.animate) {
2828
return child.props.animate;
2929
}
3030
const getFilteredState = () => {
@@ -60,7 +60,7 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
6060
// This is a copy of Wrapper.setAnimationState
6161
const setAnimationState = React.useCallback(
6262
(props, nextProps) => {
63-
if (!props.animate) {
63+
if (!props || !props.animate) {
6464
return;
6565
}
6666
if (props.animate.parentState) {

0 commit comments

Comments
 (0)