question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CountUp starts over on re-renders

See original GitHub issue

I have a functional component that draws a chart and overlays a CountUp on top.

<CountUp className="kpi-text" start={0} end={value} suffix={props.suffix} formattingFn={formatGrouping} duration={4} />

How can I make the CountUp only render if the start or end value have changed?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
mmarkelovcommented, Sep 10, 2021

Thanks guys! I could reproduce it and already fixed this. It should be fine in 6.0.0-1. And I think that i’ll publish this as stable release soon

1reaction
kershnerdcommented, Sep 9, 2021

Even though my props didn’t change, my component re-rendered higher up the tree which caused my component that had the CountUp to re-animate.

I wasn’t able to fix this directly but using a memoization seemed to work.

Import memo from react:

import React, { useEffect, memo } from 'react';

At the bottom when you export your component:

export default memo(AveragePeopleInLine);

This will force the component to not re-render if the props have not changed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useCountup seems to start on mount rather that only ... - GitHub
I have the hook in a component, where I call start() from a scroll listener and it works perfectly fine. However, I have...
Read more >
React: How can I get a count up to load only once?
This component is used on multiple pages, and I want the component to conduct the count-up only once, on the first time it...
Read more >
One simple trick to optimize React re-renders - Kent C. Dodds
When that's run, "counter rendered" will be logged to the console initially, and each time the count is incremented, "counter rendered" will be ......
Read more >
react-countup - Bountysource
formattingFn to rerender if i changed it's inner params . const countUpProps = { start: start, end: end, duration: duration , separator: separator, ......
Read more >
How many re-renders is too many? - Alex Sidorenko
My React component re-renders 5 times. Is this too many? What about 10 times or 20? When should I start optimizing?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found