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

Replace addEvents HOC with custom hook #2007

Closed
wants to merge 10 commits into from

Conversation

becca-bailey
Copy link
Contributor

This is the work I have done so far to refactor the addEvents HOC to a custom hook in order to get a better handle on how many times the parent component is re-rendering. This is implemented in VictoryBar, and works with events and animations.

@@ -13,11 +13,13 @@
"@babel/transform-spread",
"@babel/transform-template-literals",
"@babel/proposal-object-rest-spread",
"@babel/plugin-proposal-export-namespace-from"
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-optional-chaining"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still getting warnings due to this plugin - I will either need to fix webpack to resolve these warnings or take out this plugin.


export default addEvents(VictoryBar);
return <VictoryBar {...props} />;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure whether this is the right solution, but we still needed some sort of wrapper component in order to access the VictoryTransition props in the main component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it stays, it probably needs a better name.

}, [sharedEvents]);

const baseProps = React.useMemo(() => {
const sharedParentState = getSharedEventState(KEYS.PARENT, KEYS.PARENT);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically a copy of addEvents for now, but long term I would love to move away from getting this state from the sharedEvents prop. Passing in sharedEvents is causing additional re-rendering, as it is updating the props for all the data components regardless of whether each individual component is changing. It also makes it difficult to memoize props, like in #2006 where I needed to iterate through children to take out this prop. I may continue to work on this and create some sort top-level shared events context rather than using this prop.

@becca-bailey becca-bailey deleted the improvement/use-events-hook branch March 1, 2022 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant