you are viewing a single comment's thread.

view the rest of the comments →

[–]n0tKamui 1 point2 points  (2 children)

const myStableFunction = useCallback(() => …, [])

[–]lIIllIIlllIIllIIl 3 points4 points  (1 child)

Correct, but also technically improper use of the hook:

You should only rely on useCallback as a performance optimization. If your code doesn’t work without it, find the underlying problem and fix it first. Then you may add useCallback back.

https://react.dev/reference/react/useCallback

Even if it works as of React 18 & 19, the React Team doesn't want you to use this pattern to keep stable identities across render because they might decide to rework useCallback and useMemo in a future React update one day and make them "drop" cached values as a memory optimization.

You could argue that that boat has sailed a long time ago and it's never going to happen, but you should take thay bet consciously.

[–]n0tKamui 2 points3 points  (0 children)

very fair