@@ -8,9 +8,13 @@ import { FaDownload } from 'react-icons/fa'
88import convexImageWhite from '~/images/convex-white.svg'
99import convexImageDark from '~/images/convex-dark.svg'
1010
11- const counterIntervalMs = 500
12-
13- const StableCounter = ( { value } : { value ?: number } ) => {
11+ const StableCounter = ( {
12+ value,
13+ intervalMs,
14+ } : {
15+ value ?: number
16+ intervalMs ?: number
17+ } ) => {
1418 const dummyString = Number (
1519 Array ( value ?. toString ( ) . length ?? 1 )
1620 . fill ( '8' )
@@ -23,14 +27,19 @@ const StableCounter = ({ value }: { value?: number }) => {
2327 < span className = "opacity-0" > { dummyString } </ span >
2428 < span className = "absolute -top-0.5 left-0" >
2529 < NumberFlow
30+ // Defer to counter hook calculated interval
31+ spinTiming = { {
32+ duration : intervalMs ,
33+ easing : 'linear' ,
34+ } }
35+ // Slow horizontal shift animation (due to differing number widths)
2636 transformTiming = { {
27- duration : counterIntervalMs ,
37+ duration : 1000 ,
2838 easing : 'linear' ,
2939 } }
3040 value = { value }
3141 trend = { 1 }
3242 continuous
33- isolate
3443 willChange
3544 />
3645 </ span >
@@ -43,10 +52,8 @@ const NpmDownloadCounter = ({
4352} : {
4453 npmData : Parameters < typeof useNpmDownloadCounter > [ 0 ]
4554} ) => {
46- const liveNpmDownloadCount = useNpmDownloadCounter ( npmData , {
47- intervalMs : counterIntervalMs ,
48- } )
49- return < StableCounter value = { liveNpmDownloadCount } />
55+ const { count, intervalMs } = useNpmDownloadCounter ( npmData )
56+ return < StableCounter value = { count } intervalMs = { intervalMs } />
5057}
5158
5259export default function OssStats ( ) {
0 commit comments