CountUp starts over on re-renders
See original GitHub issueI 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:
- Created 2 years ago
- Reactions:1
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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:
At the bottom when you export your component:
This will force the component to not re-render if the props have not changed.