You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useCallback provides a way to memoize callbacks based on whether an array of given values changes. I have been wondering if it could work like something similar to this instead:
Note that this is just a mock implementation to illustrate my idea. This hook above will always return the same function instance that is kept within the reference object, while always calling the latest version of the callback argument. This way the need to pass props to be compared is omitted which could also be an improvement to its performance.
Here is a side to side usage comparison:
functionMyComponent({title}){// Will return the memoized callback if title didn't change.constcurrent=useCallback(()=>alert(title),[title])// Will return a memoized callback, even if title changes,// while there is also no need to check if it did change.constalternative=useStatic(()=>alert(title))}
The text was updated successfully, but these errors were encountered:
useCallback provides a way to memoize callbacks based on whether an array of given values changes. I have been wondering if it could work like something similar to this instead:
Note that this is just a mock implementation to illustrate my idea. This hook above will always return the same function instance that is kept within the reference object, while always calling the latest version of the callback argument. This way the need to pass props to be compared is omitted which could also be an improvement to its performance.
Here is a side to side usage comparison:
The text was updated successfully, but these errors were encountered: