Skip to content

Improving scale management performances with memoization? #1026

Answered by williaster
soykje asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @soykje 👋 thanks for checking out visx.

It's a bit hard to follow your question without a complete example. Generally using useMemo for scale creation is recommended, so something like

const radiusScale = useMemo(() =>
  scalePower({
    domain: [0, 255],
    range: [0, VIZ_DIAMETER / 2],
    exponent: 2
  }),
  [],
);

Based on that it doesn't actually look like your scale range or domain actually ever need to change based on the data (since there are no dependencies to the data)? In that case it would only be created once / wouldn't need to be updated.

Another note is that updateScale actually returns a copy of the scale, and because you're not updating what radiusScale is pointing t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@soykje
Comment options

Answer selected by soykje
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants