-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[material-ui][docs] Change composition code snippet from useMemo()
to useCallback()
#41590
Conversation
`useCallback(fn, deps)` is equivalent to `useMemo(() => fn, deps)` but more readable. Signed-off-by: adriancuadrado <adriancuadradochavarria97@gmail.com>
Netlify deploy previewBundle size report |
useMemo()
to useCallback()
Since I'm requested as a reviewer I'll give my opinion here 🙂 but you probably want to assign a core team member. |
As far as I have understood, using I'd understand if you didn't accept it but I think it would make more sense to get rid of that lint rule altogether. I don't understand why you say it's a react anti pattern. If it is because there is a component being defined inside another, then we won't be able to explain how to deal with that use case altogether if we just remove it. |
Neither passes the react eslint rules. I have no preference for one syntax over the other, as far as I know there is no real benefit for either syntax. So I'm leaving that decision for the core team to make. My comment is mainly about my impression when I opened this page. I didn't immediately get the notion that these were snippets that explain how not to implement this. They are React anti-patterns because they not only cause rerenders when cc @mnajdova |
I agree with @Janpot—using this pattern is a React anti-pattern, even when wrapped with React.useCallback or React.memo. For more details, see the ESLint rule. I've updated the Composition docs in PR #43266, so I'll close this PR. Thanks, @adriancuadrado, for bringing this issue to light. |
useCallback(fn, deps)
is equivalent touseMemo(() => fn, deps)
but more readable.