SukkaW / foxact

React Hooks/Utils done right. For Browser, SSR, and React Server Components.
https://foxact.skk.moe
MIT License
304 stars 10 forks source link

fix(use-debounced-value): unable set and debounce value which is func… #9

Closed NWYLZW closed 12 months ago

NWYLZW commented 12 months ago

If my target value type is function, it can't debounced which be used as state init function.

const func: ((a: boolean) => string) | undefined = useMemo(() => xxx, [])
const a = useDebouncedValue(func, 100)

And if I want to set state init value, it unable infer right type.

const a = useDebouncedValue(() => 1, 100)
// a type: () => number

But a real value is number.

SukkaW commented 12 months ago

Close as won't merge.

You should never debounce a function as a value itself.