Skip to content
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

[React 19], useCallback not needed now!!! #31913

Open
TonyFTannous-Byd opened this issue Dec 26, 2024 · 2 comments
Open

[React 19], useCallback not needed now!!! #31913

TonyFTannous-Byd opened this issue Dec 26, 2024 · 2 comments
Labels

Comments

@TonyFTannous-Byd
Copy link

TonyFTannous-Byd commented Dec 26, 2024

my question is, in react 19, the usage of useCallback is deprecated, means react automatically memoize the functions in my functional component? or only memoize the function that hasn't any dependencies. please more clarification about this.
if it is not required, and my app already i used useCallback, and memo... i have any side effect if i continue used it or i need to removed from my app if i want to switch from 18 to 19

thanks.

@HAWKZ4
Copy link

HAWKZ4 commented Dec 26, 2024

Hi @TonyFTannous-Byd

  1. useCallback is not deprecated in React 19, but React's rendering improvements may reduce its necessity in some cases

  2. React does not automatically memoize functions. You still need useCallback to explicitly memoize functions, especially those with dependencies

  3. Keeping useCallback when upgrading to React 19 has no harmful side effects, but it might add unnecessary complexity if
    overused

  4. Remove useCallback only where it doesn’t provide meaningful performance benefits, especially in non-performance-critical parts of your app

  5. Use tools like React DevTools to profile your app. Keep useCallback where it helps, and simplify your code where it doesn’t

Recommendation: Gradually audit your use of useCallback :

  • keep it where necessary and remove it elsewhere to simplify your code

@TonyFTannous-Byd
Copy link
Author

Hi @HAWKZ4 , thanks for your answere
if you use React 19 only, you are right but using with it new react compiler (npm install -D eslint-plugin-react-compiler), no need for useCallback memo ....
this what react 19 documentation told (https://react.dev/learn/react-compiler)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants