Skip to content

Commit

Permalink
Fix victory-group animation (#2717)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenanYusuf authored Jan 16, 2024
1 parent cb630fa commit 4556f3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

1 comment on commit 4556f3d

@vercel
Copy link

@vercel vercel bot commented on 4556f3d Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.