Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix victory-group animation #2717

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-brooms-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"victory-group": patch
---

Fix victory-group animation
17 changes: 10 additions & 7 deletions packages/victory-group/src/victory-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ const VictoryGroupBase: React.FC<VictoryGroupProps> = (initialProps) => {
const role = VictoryGroup?.role;
const { getAnimationProps, setAnimationState, getProps } =
Hooks.useAnimationState();
initialProps = { ...defaultProps, ...initialProps };
const props = getProps(initialProps);
const propsWithDefaults = React.useMemo(
() => ({ ...defaultProps, ...initialProps }),
[initialProps],
);
const props = getProps(propsWithDefaults);

const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
const {
Expand Down Expand Up @@ -132,8 +135,8 @@ const VictoryGroupBase: React.FC<VictoryGroupProps> = (initialProps) => {
]);

const userProps = React.useMemo(
() => UserProps.getSafeUserProps(initialProps),
[initialProps],
() => UserProps.getSafeUserProps(propsWithDefaults),
[propsWithDefaults],
);

const container = React.useMemo(() => {
Expand All @@ -160,16 +163,16 @@ const VictoryGroupBase: React.FC<VictoryGroupProps> = (initialProps) => {
return Wrapper.getAllEvents(props);
}, [props]);

const previousProps = Hooks.usePreviousProps(initialProps);
const previousProps = Hooks.usePreviousProps(propsWithDefaults);

React.useEffect(() => {
// This is called before dismount to keep state in sync
return () => {
if (initialProps.animate) {
if (propsWithDefaults.animate) {
setAnimationState(previousProps, props);
}
};
}, [setAnimationState, previousProps, initialProps, props]);
}, [setAnimationState, previousProps, propsWithDefaults, props]);

if (!isEmpty(events)) {
return (
Expand Down