@@ -5,12 +5,16 @@ import type { NpmStats } from '~/utils/stats.server'
55 * Hook to animate NPM download count using direct DOM updates.
66 * Uses setInterval to minimize overhead - updates only when count changes.
77 */
8- export function useNpmDownloadCounter ( npmData : NpmStats ) : React . RefCallback < HTMLElement > {
8+ export function useNpmDownloadCounter (
9+ npmData : NpmStats ,
10+ ) : React . RefCallback < HTMLElement > {
911 const baseCount = npmData . totalDownloads ?? 0
1012 const ratePerDay = npmData . ratePerDay ?? 0
1113 const updatedAt = npmData . updatedAt ?? Date . now ( )
1214
13- const intervalRef = useRef < ReturnType < typeof setInterval > | undefined > ( undefined )
15+ const intervalRef = useRef < ReturnType < typeof setInterval > | undefined > (
16+ undefined ,
17+ )
1418 const elementRef = useRef < HTMLElement | null > ( null )
1519 const lastCountRef = useRef < number | null > ( null )
1620
@@ -48,17 +52,20 @@ export function useNpmDownloadCounter(npmData: NpmStats): React.RefCallback<HTML
4852 }
4953 } , [ baseCount , ratePerDay , updatedAt ] )
5054
51- const refCallback = useCallback ( ( node : HTMLElement | null ) => {
52- elementRef . current = node
53- if ( node ) {
54- const msPerDay = 24 * 60 * 60 * 1000
55- const ratePerMs = ratePerDay / msPerDay
56- const elapsedMs = Date . now ( ) - updatedAt
57- const count = Math . round ( baseCount + ratePerMs * elapsedMs )
58- lastCountRef . current = count
59- node . textContent = count . toLocaleString ( )
60- }
61- } , [ baseCount , ratePerDay , updatedAt ] )
55+ const refCallback = useCallback (
56+ ( node : HTMLElement | null ) => {
57+ elementRef . current = node
58+ if ( node ) {
59+ const msPerDay = 24 * 60 * 60 * 1000
60+ const ratePerMs = ratePerDay / msPerDay
61+ const elapsedMs = Date . now ( ) - updatedAt
62+ const count = Math . round ( baseCount + ratePerMs * elapsedMs )
63+ lastCountRef . current = count
64+ node . textContent = count . toLocaleString ( )
65+ }
66+ } ,
67+ [ baseCount , ratePerDay , updatedAt ] ,
68+ )
6269
6370 return refCallback
6471}
0 commit comments