-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
Memoized utils methods for useMap #592
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need some additional asserts for checking the callbacks instances. If after adding that the test passes, I'm happy with the implementation :)
utils.set('foo', 'baz'); | ||
}); | ||
|
||
expect(result.current[1]).toBe(utils); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are checking here that utils
object is the same instance, but that doesn't mean that returned callbacks are same instances, so you would have to check that utils.get
is result.current[1].get
and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact it does mean that internals are the same (due to useMemo
instead of bunch of useCallback
), but that, more precise check of result.current[1].get
wont be excessive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed working just fine, but I guess an additionnal test assertion can make it more visible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, just reading the implementation you can see how it will the same instance, but better to assert that explicitly so if tomorrow that implementation changes, the test will check for proper callback instance, not just the object.
🎉 This PR is included in version 12.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hey guys,
Here is my proposal following the issue #456
All feedbacks are more than welcome
Cheers