A configurable React component wrapper around CountUp.js.
Click here to get to the previous docs.
- Installation
- Usage
- API
- Props
className: stringdecimal: stringdecimals: numberdelay: ?numberduration: numberend: numberprefix: stringredraw: booleanseparator: stringstart: numbersuffix: stringuseEasing: booleaneasingFn: (t: number, b: number, c: number, d: number) => numberformattingFn: (value: number) => stringonEnd: ({ pauseResume, reset, start, update }) => voidonStart: ({ pauseResume, reset, update }) => voidonPauseResume: ({ reset, start, update }) => voidonReset: ({ pauseResume, start, update }) => voidonUpdate: ({ pauseResume, reset, start }) => void
- Render props
- Props
- Protips
- License
yarn add react-countupimport CountUp from 'react-countup';<CountUp end={100} />This will start a count up transition from 0 to 100 on render.
<CountUp
start={-875.039}
end={160527.012}
duration={2.75}
separator=" "
decimals={4}
decimal=","
prefix="EUR "
suffix=" left"
onEnd={() => console.log('Ended! π')}
onStart={() => console.log('Started! π¨')}
>
{({ countUpRef, start }) => (
<div>
<span ref={countUpRef} />
<button onClick={start}>Start</button>
</div>
)}
</CountUp>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}.
<CountUp start={0} end={100}>
{({ countUpRef, start }) => (
<div>
<span ref={countUpRef} />
<button onClick={start}>Start</button>
</div>
)}
</CountUp>Render start value but start transition on first render:
<CountUp start={0} end={100} delay={0}>
{({ countUpRef }) => (
<div>
<span ref={countUpRef} />
</div>
)}
</CountUp>Note that delay={0} will automatically start the count up.
<CountUp delay={2} end={100} />CSS class name of the span element.
Note: This won't be applied when using CountUp with render props.
Specifies decimal character.
Default: .
Amount of decimals to display.
Default: 0
Delay in seconds before starting the transition.
Default: null
Note:
delay={0}will automatically start the count up.
Duration in seconds.
Default: 2
Target value.
Static text before the transitioning value.
Forces count up transition on every component update.
Default: false
Specifies character of thousands separator.
Initial value.
Default: 0
Static text after the transitioning value.
Enables easing. Set to false for a linear transition.
Default: true
Easing function. Click here for more details.
Default: easeInExpo
Function to customize the formatting of the number
Callback function on transition end.
Callback function on transition start.
Callback function on pause or resume.
Callback function on reset.
Callback function on update.
Ref to hook the countUp instance to
Pauses or resumes the transition
Resets to initial value
Starts or restarts the transition
Updates transition to the new end value (if given)
By default, the animation is triggered if any of the following props has changed:
durationendstart
If redraw is set to true your component will start the transition on every component update.
MIT
