useLatestFn

Function
useLatestFn<T>(fnT): T

A Hook that returns a memoized function which has the same signature as the input function and always calls the latest version of the input function.

Type Parameters

ParameterType
T(argsany[]) => any

Parameters

ParameterType
fnT

Returns 

T

example:

Use dark colors for code blocksCopy
1
2
3
4
5
const handleClick = useLatestFn(() => {
console.log(value)
})

return <button onClick={handleClick}>Click me</button>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.