feat: Init

This commit is contained in:
beilunyang
2024-12-16 01:35:08 +08:00
commit cc7e5003c5
73 changed files with 15001 additions and 0 deletions

19
app/hooks/use-throttle.ts Normal file
View File

@@ -0,0 +1,19 @@
import { useCallback, useRef } from 'react'
export function useThrottle<T extends (...args: any[]) => void>(
fn: T,
delay: number
): T {
const lastRun = useRef(Date.now())
return useCallback(
((...args) => {
const now = Date.now()
if (now - lastRun.current >= delay) {
fn(...args)
lastRun.current = now
}
}) as T,
[fn, delay]
)
}