useStableCallback
Returns a memoized version of your function that maintains a stable reference, but also can read the latest scope (props and state) of the component in which it is used. Useful for preventing unnecessary re-renders.
- @param
callback- Function to stabilize
Example
const stableCallback = useStableCallback(() => getRandomValue())
stableCallback()
// always returns the latest value, but the reference to the
// callback itself is stable and never changes