Count should start after the component is in view.
See original GitHub issueIs it possible for countup to begin once we scrolldown to the component , currently the count starts as soon as the page is rendered. Animation happens only once(which is good)after the page is loaded, but I would like the counter not to begin soon after the page is loaded, but when user scrolls down to the component first time. My code looks like this:
render() {
return (
<div className={style.componentName}>
<h2>Heading</h2>
<div className={style.col}>
<div>My counter</div>
<CountUp className={style.countup} decimals={1} start={0} end={25} suffix=" %" duration={3} />
</div>
</div>)}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
React countup animation starts immediately after the page ...
I would use that approach to start the counter once a user has scrolled to the required distance. import React, { Component }...
Read more >Practical React - 6 - CountUp - YouTube
Practical React - 6 - CountUp. Watch later. Share. Copy link. Info. Shopping. Tap to unmute. If playback doesn't begin shortly, ...
Read more >Rendering and Updating Data using Component Lifecycle ...
A React component can be created using a function or a class-based component, and the class-based component can use different lifecycle hooks.
Read more >Hooks API Reference - React
The function will receive the previous value, and return an updated value. Here's an example of a counter component that uses both forms...
Read more >The Guide to Learning React Hooks (Examples & Tutorials)
Let's start with creating the inputRef property. At the top of your todo component, add the following property: const inputRef = useRef();. We...
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
Why not adding an option out of the box to
React CountUP
to handle animation when component is in the viewport? 🤔@evatd Yes, Refer : https://stackoverflow.com/questions/51044090/react-countup-animation-starts-immediately-after-the-page-loading-should-start. we do it using react-visibility sensor package The second answer by Tadas Antanavicius helps. I’ve also updated my question with my solution. Let me know if it works:) If you want the count up to start evertime component is scrolled to view, then don’t set a state