@vx/tooltip is expensive with renders
withTooltip has no optimizations. Everytime the chart under tooltip needs to update the tooltipData it causes a rerender of the entire chart along with the tooltip. Perhaps it would be better with a react context or small redux state?
Hi @louispvb, at the moment vx still supports React 15 so we can't move to the "new" Context api released in 16.3 just yet. Another option would be a hook, but same thing as context as hooks were released in 16.8. These would be better solutions out-of-box for vx but until we drop support React 15 we're not ready for them yet.
So, what is the fix to optimize performance and prevent the chart from re-rendering unnecessarily when the tooltip changes? As they are just react components we can use shouldComponentUpdate() and returning false when only the tooltip props have changed.
pseudo code example:
const MyChart = withTooltip(/** ... */);
class ChartComponent extends React.Component {
shouldComponentUpdate(nextProps) {
// ...
}
}
// render
<MyChart>
<ChartComponent {/** ... */} />
<TooltipComponent {/** ... */} />
</MyChart>
For a more detailed example:
Hope this helps!
Thanks @hshoff, good advice.