-
Notifications
You must be signed in to change notification settings - Fork 6
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
Difference with use-memo-one? #3
Comments
They dont quite solve the same problem. useConstant(fn) is like useMemoOne(fn, []). This means that useConstant doesnt allow for cache invalidation, it just creates something and use created thing through the whole lifetime of the component - it’s implementation is much shorter than useMemoOne and for simplicity i prefer this one, especially because i dont have any use cases which useMemoOne would solve for me at the moment. useMemo and useConstant are everything I need. Also - mine library was released before the other one. Not that it matter anyhow (they solve similar, but imho different problem), but saying that there is already other similar project might be a little bit confusing ;) |
Is that really the shortest implementation? I'm not sure why this wasn't used:
It also runs only once. |
See - #4 (comment) |
I have a feeling it will not work in Concurrent Mode.
|
If React decides to throw away the whole chunk of work then it should also throw away whatever got stored in a ref and then with the next render the value should be reinitialized - at least this is my current understanding and this is how it behaved within the |
I think it is just like |
There is already a "popular" project that aims to solve the same problem: https://github.com/alexreardon/use-memo-one
What's the difference?
Here the implementation: https://github.com/alexreardon/use-memo-one/blob/v1.1.0/src/index.js
The text was updated successfully, but these errors were encountered: