useStableFn

A React Hook that returns a function whose memory address will never change.

Demo

Try to increase the counter to update the component to trigger re-render, you will see that the function's memory address will never change, so the toast will never show up.

Source
Count:
0

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const stableFn = useStableFn(fn)

Fn

The function whose memory address will be stable.

Returns

A same shape function, but its memory address will never change.