A configurable React component wrapper around CountUp.js to count up numbers.
Check out the live demo.
Make sure you have a compatible version of and 15.x.x installed in your project.
npm install react-countup --saveimport React from 'react';
import { render } from 'react-dom';
import CountUp from 'react-countup';
render(
<CountUp start={0} end={160526} />,
document.getElementById('root')
);import React from 'react';
import { render } from 'react-dom';
import CountUp from 'react-countup';
const onComplete = () => {
console.log('Completed! π');
};
const onStart = () => {
console.log('Started! π¨');
};
render(
<CountUp
className="custom-count"
start={160527.0127}
end={-875}
duration={2.75}
useEasing={true}
separator=" "
decimal=","
prefix="EUR "
suffix=" left"
onComplete={onComplete}
onStart={onStart}
/>,
document.getElementById('root'),
);The start number from which the should start from
Target number to count up
Duration of count up animation in seconds
Amount of decimals
Use "easeOutExpo" if true
Group thousands by separator character
Specifies character of thousands separator
Specifies decimal character
Static text before the animating value
Static text after the animating value
CSS class name of the span element
If true, your component will always animate on every re-render.
Method called after animation has completed
Method called before animation starts
Method to customize easing the function. See also here
Method to customize the formatting of the number
By default, the animation triggered if any of the follow props has changed:
durationendstart
You can set redraw to true If you want your component to always animate on every re-render.
import React, { Component } from 'react';
import CountUp, { startAnimation } from 'react-countup';
const MyComponent = () => (
<div>
<CountUp className="CountUp" start={0} end={100} duration={3} ref={(countUp) => {
this.myCountUp = countUp;
}} />
<button className="Button" onClick={(event) => {
startAnimation(this.myCountUp);
}}>Animate me!</button>
</div>
);
export default App;MIT
