react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

Clarification on useCallback function name on beta docs

Open kkyusufk opened this issue 3 years ago • 4 comments
trafficstars

In the react beta docs, useCallback api reference page gives the following example image

I think the constant naming memoizedFn leads to some confusion on what useCallback does. People tend to assume that useCallback actually memoizes the function but it does not do that. It returns the same instance of the function between re-renders. An appropriate name of that variable should be originalFn. I maybe wrong so please let me know if the above makes sense.

Big fan of the beta docs btw ❤️ , beautiful documentation and excellent examples!

kkyusufk avatar Sep 17 '22 16:09 kkyusufk

I agree with the concern but I don’t think your suggestion is much clearer.

gaearon avatar Sep 17 '22 16:09 gaearon

how about a simple returnedFn? Since useCallback does return a function. Maybe I can send a small PR and we can start a discussion on it. More folks can chime in.

kkyusufk avatar Sep 17 '22 16:09 kkyusufk

I don't think that's better either since you could prepend any name with returned and it wouldn't change the meaning.

gaearon avatar Sep 17 '22 19:09 gaearon

I agree with @gaearon; it would change the meaning

lxmarinkovic avatar Sep 18 '22 20:09 lxmarinkovic