A React component wrapper around CountUp.js
npm install react-countup-es





A configurable React component wrapper around CountUp.js.
Click here to view on CodeSandbox.
Click here to get to the previous docs.
- Installation
- Usage
- Simple example
- Render prop example
- More examples
- Manually start with render prop
- Autostart with render prop
- Delay start
- Hook
- API
- Props
- className: string
- decimal: string
- decimals: number
- delay: ?number
- duration: number
- end: number
- prefix: string
- redraw: boolean
- preserveValue: boolean
- separator: string
- start: number
- startOnMount: boolean
- suffix: string
- useEasing: boolean
- easingFn: (t: number, b: number, c: number, d: number) => number
- formattingFn: (value: number) => string
- onEnd: ({ pauseResume, reset, start, update }) => void
- onStart: ({ pauseResume, reset, update }) => void
- onPauseResume: ({ reset, start, update }) => void
- onReset: ({ pauseResume, start, update }) => void
- onUpdate: ({ pauseResume, reset, start }) => void
- Render props
- countUpRef: () => void
- pauseResume: () => void
- reset: () => void
- start: () => void
- update: (newEnd: number?) => void
- Protips
- License
``bash`
yarn add react-countup
`js`
import CountUp from 'react-countup';
`js`
This will start a count up transition from 0 to 100 on render.
`js`
end={160527.012}
duration={2.75}
separator=" "
decimals={4}
decimal=","
prefix="EUR "
suffix=" left"
onEnd={() => console.log('Ended! 👏')}
onStart={() => console.log('Started! 💨')}
>
{({ countUpRef, start }) => (
)}
The transition won't start on initial render as it needs to be triggered manually here.
> Tip: If you need to start the render prop component immediately, you can set delay={0}.
#### Manually start with render prop
`js`
{({ countUpRef, start }) => (
)}
#### Autostart with render prop
Render start value but start transition on first render:
`js`
{({ countUpRef }) => (
)}
Note that delay={0} will automatically start the count up.
#### Delay start
`js`
#### Simple example
`js
import { useCountUp } from 'react-countup';
const SimpleHook = () => {
const { countUp } = useCountUp({ end: 1234567 });
return
#### Complete example
`js
import { useCountUp } from 'react-countup';const CompleteHook = () => {
const { countUp, start, pauseResume, reset, update } = useCountUp({
start: 0,
end: 1234567,
delay: 1000,
duration: 5,
onReset: () => console.log('Resetted!'),
onUpdate: () => console.log('Updated!'),
onPauseResume: () => console.log('Paused or resumed!'),
onStart: ({ pauseResume }) => console.log(pauseResume),
onEnd: ({ pauseResume }) => console.log(pauseResume),
});
return (
{countUp}
);
};
`API
$3
####
className: stringCSS class name of the span element.
> Note: This won't be applied when using CountUp with render props.
####
decimal: stringSpecifies decimal character.
Default:
.####
decimals: numberAmount of decimals to display.
Default:
0####
delay: ?numberDelay in seconds before starting the transition.
Default:
null> Note:
delay={0} will automatically start the count up.####
duration: numberDuration in seconds.
Default:
2####
end: numberTarget value.
####
prefix: stringStatic text before the transitioning value.
####
redraw: booleanForces count up transition on every component update.
Default:
false####
preserveValue: booleanSave previously ended number to start every new animation from it.
Default:
false####
separator: stringSpecifies character of thousands separator.
####
start: numberInitial value.
Default:
0####
startOnMount: booleanUse for start counter on mount for hook usage.
Default:
true####
suffix: stringStatic text after the transitioning value.
####
useEasing: booleanEnables easing. Set to
false for a linear transition.Default:
true####
easingFn: (t: number, b: number, c: number, d: number) => numberEasing function. Click here for more details.
easeInExpo####
formattingFn: (value: number) => stringFunction to customize the formatting of the number
####
onEnd: ({ pauseResume, reset, start, update }) => voidCallback function on transition end.
####
onStart: ({ pauseResume, reset, update }) => voidCallback function on transition start.
####
onPauseResume: ({ reset, start, update }) => voidCallback function on pause or resume.
####
onReset: ({ pauseResume, start, update }) => voidCallback function on reset.
####
onUpdate: ({ pauseResume, reset, start }) => voidCallback function on update.
$3
####
countUpRef: () => voidRef to hook the countUp instance to
####
pauseResume: () => voidPauses or resumes the transition
####
reset: () => voidResets to initial value
####
start: () => voidStarts or restarts the transition
####
update: (newEnd: number?) => voidUpdates transition to the new end value (if given)
Protips
By default, the animation is triggered if any of the following props has changed:
-
duration
- end
- startIf
redraw is set to true` your component will start the transition on every component update.MIT