A hook that is able to persist functions. In theory, useMemoizedFn
could be used to replace useCallback
.
In some scenarios, we need to use useCallback
to cache a function, but when deps (the second parameter) changes, the function will be regenerated, thus causing the function reference to change.
By using useMemoizedFn
, you can omit the second parameter deps, and ensure that the function reference never changes.
Basic usage of useMemoizedFn hook.
Property | Description | Type | Default |
---|---|---|---|
fn | Function that requires persistence | (...args: any[]) => any | - |
Property | Description | Type |
---|---|---|
fn | Function (the function reference never changes) | (...args: any[]) => any |