diff --git a/packages/victory-group/src/victory-group.tsx b/packages/victory-group/src/victory-group.tsx index f81cba9ec..7d587e00c 100644 --- a/packages/victory-group/src/victory-group.tsx +++ b/packages/victory-group/src/victory-group.tsx @@ -67,8 +67,11 @@ const VictoryGroupBase: React.FC = (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 { @@ -132,8 +135,8 @@ const VictoryGroupBase: React.FC = (initialProps) => { ]); const userProps = React.useMemo( - () => UserProps.getSafeUserProps(initialProps), - [initialProps], + () => UserProps.getSafeUserProps(propsWithDefaults), + [propsWithDefaults], ); const container = React.useMemo(() => { @@ -160,16 +163,16 @@ const VictoryGroupBase: React.FC = (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 (