Replies: 2 comments 4 replies
-
| You're right. The value is small. | 
Beta Was this translation helpful? Give feedback.
                  
                    3 replies
                  
                
            -
| I'm interested in this too. Is there any advantage to using 'useCallback' instead of local functions? It seems  int calculate(int value) => value + value;vs. final calculate = useCallback((int value) => value + value); | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently exploring the Flutter Hooks package and I am trying to understand the practical utility of the
useCallbackhook. I'd appreciate some insights or clarifications on my understanding.Context
In the React ecosystem,
useCallbackis often utilized alongsideReact.memofor optimizing performance. It helps in avoiding unnecessary re-renders by retaining the callback function's instance, ensuring that the comparison of props remains consistent even across different renders.Concern
In the Flutter ecosystem, there isn't a direct equivalent of
React.memo. Although we can use const constructors to minimize rebuilds, function objects can’t be constant. This implies that any widget receiving a function object as a property can’t be made const, thus undermining the potential benefits ofuseCallback.Question
Is my understanding correct that
useCallbackmight not offer significant benefits in Flutter, given the absence of a memoization mechanism akin toReact.memo? I am eager to understand if there are specific scenarios or use cases whereuseCallbackproves beneficial in Flutter, that I might not be considering. Thanks.Beta Was this translation helpful? Give feedback.
All reactions