-
-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improvement: omit useDebounceCallback func arg from dependency array #501
base: master
Are you sure you want to change the base?
improvement: omit useDebounceCallback func arg from dependency array #501
Conversation
|
a723141
to
3f99d23
Compare
Hi @therour, your PR does not compile yet. |
3f99d23
to
4edcd55
Compare
@juliencrn thanks for the response, I think the Generic for currently was DebouncedState<T extends (...args: any) => ReturnType<T>>
|
OK I understand, that it can be fixed from developer perspective by memoize the callback arg const debouncedIncrement = useDebounceCallback(
React.useCallback(() => setValue(val) => val + 1, []),
500
) |
Improvement
Problem
debouncedIncrement
anddebouncedFn
will always create new reference every re-render. this will be dangerous if this debounced function is passed to any react hooks dependency arrayoptions
object, the user's providedoptions
object also not necessarily memoized, so we can just pass it's values to dependency array instead of the object reference itselfSolution
func
intouseRef
, so we dont need to pass it to theuseMemo
dependency arrayoptions
in theuseMemo
dependency arrayFix
Current behavior
isPending()
always returntrue
, it is onlyfalse
on first renderExpectation
based on type comments