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
useCallback usage #456
Comments
What is your use case? |
Hi, I tried to use IMO, it would be a good idea to propose the most stable (i.e. memoized) return values possible. Similar to the way Cheers, |
I agree with @Granipouss: ideally all these returned callbacks should be memoized to always return same instance if same args provided. We have fixed few of them, in previous PRs like this one #570 @AjaxSolutions could you create a PR for fixing those callbacks on |
Looked inside the hook and got trrified🙈 IMO it should use ref to a storage value, this way it can have the maximum performance and the only callbacks instance with no need to update them ever. |
Callbacks returned should be memoized, but I'm not so sure the actual object should be memoized too. You need to return a new object when updated, otherwise the component using this hook won't know when the object has been updated. Think about |
@Belco90 the component re-rendering can be done with a single |
Sure, but that's re-implementing the natural behavior of I would go for leaving the setState and just memoize the callbacks. As you mentioned, should be easy to solve, all current tests should pass and you can add a new one to check callbacks returned are always same instance. |
@Belco90 the ref is needed to solve performance issue that, i believe, will appear already on 500-1000 entities inside the state. |
As far as I know, multiple I believe the actions are meant to be used with destructuring (could be wrong tho), so I see no need to memoized the returned object. It would be safer tho. |
@xobotyi I don't think that would raise a performance issue using |
I just found this and seems interesting for identifying which React hook suits better for each case :) https://twitter.com/tylermcginnis/status/1169667360795459584 |
Why the get, set, remove and remove functions are not wrapped in useCallback?
https://github.com/streamich/react-use/blob/master/src/useMap.ts
The same question applies to functions returned by useList.
The text was updated successfully, but these errors were encountered: