Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
use-count-up
Advanced tools
Only 4.5KB React hook to animate counting up or down to a number, infinity, or even beyond.
Only 4.5KB React hook to animate counting up or down to a number, infinity, or even beyond.
Display your data in an attractive way to make sure the important numbers are highlighted in an eye-catching format.
Unlike other similar solutions, this hook allows you to count up/down with or without providing end values.
yarn add use-count-up
or
npm install use-count-up
import { useCountUp } from 'use-count-up';
const isCounting = true;
const config = {
start: 450,
end: 1320,
duration: 3.2,
formatter: value => `${Math.ceil(value)}$`
};
const MyComponent = () => {
const value = useCountUp(isCounting, config);
return value;
};
The function takes two agruments and returns the value from the formatter
method.
const useCountUp = (
isCounting: boolean,
config?: {
start?: number,
end?: number,
duration?: number,
onComplete?: () => void,
easing?: (t: number, b: number, c: number, d: number) => number,
formatter?: (value: number) => number|string|node,
}
) => number|string|node;
isCounting: boolean
Default:
isCounting = false
Toggle the counting animation. It can be used to start the animation when the elmenet enters the viewport. If config.end
is not provided, the animation will continue to Infinity
.
config: object
Default:
config = {}
Optional configuration object with the following properties and methods:
start: number
Default:
start = 0
Initial value.
end: number
Default:
end = undefined
Target value.
duration: number
Default:
duration = undefined
Animation duration in seconds. Example: 3
, 4.2
, 0.5
onComplete: () => void
Default:
onComplete = undefined
On animation complete event handler.
easing: (t: number, b: number, c: number, d: number) => number,
Default:
easing = (t, b, c, d) => { t /= d; t--; return c*(t*t*t*t*t + 1) + b; }
// easeOutQuint
t
- current time
b
- start value
c
- change in value
d
- duration
Easing function to control how the animation is progressing. There are a bunch of functions that can be used to change that behaviour.
formatter: (value: number) => number|string|node
Default:
formatter = value => Math.round(value)
A function that formats the output value. It can be used to add prefix or suffix to the value. A good formatting option is to use toLocaleString
, which will give the correct decimal and thousand separators.
1.0.0 (Oct 6th, 2019)
Implemented enhancements:
FAQs
React/React Native component and hook to animate counting up or down to a number
The npm package use-count-up receives a total of 23,154 weekly downloads. As such, use-count-up popularity was classified as popular.
We found that use-count-up demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.