-
Is there a rule to disallow inline function for callbacks in React? <Button
onClick={() => {
console.log("foo");
}}
/> and this would be the valid way: const onButtonClick = useCallback(() => {
console.log("foo");
}, []); <Button
onClick={onButtonClick}
/> |
Beta Was this translation helpful? Give feedback.
Answered by
arendjr
Nov 24, 2024
Replies: 1 comment 4 replies
-
I'm not aware of us having one, no. I'm also not sure it would be a good idea. There are many situations where |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
VPKSoft
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not aware of us having one, no.
I'm also not sure it would be a good idea. There are many situations where
useCallback()
doesn't add any value, such as when passing to a plain HTML element or a non-memoized component. Plus it would be difficult to avoid false negatives, for instance when we cannot trace the origin of a variable that is passed instead of a plain function.