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.

Count should start after the component is in view.

See original GitHub issue

Is 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
aress31commented, Feb 18, 2022

Why not adding an option out of the box to React CountUP to handle animation when component is in the viewport? 🤔

1reaction
Byloorcommented, Jul 7, 2018

@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

Read more comments on GitHub >

github_iconTop 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 >

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