Import
Signature
Parameters
The target number to count up to.
Animation duration in milliseconds. Defaults to 3000ms (3 seconds).
Returns
The current animated count value.
Usage
Implementation Details
- Easing Function: Uses cubic easing (
1 - (1 - t)³) for smooth animation - Performance: Utilizes
requestAnimationFramefor optimal performance - Precision: Floors the animated value and ensures exact target at completion
- Cleanup: Properly cancels animation frame on component unmount
Examples
Basic Counter
Fast Animation
Slow Animation
Common Use Cases
- Animating statistics on page load
- Dashboard metric displays
- Achievement counters
- Progress indicators
- Loading state animations
The hook starts counting from 0 whenever the component mounts. If you need to restart the animation, remount the component or use a key prop.