-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
useComputed doesn't update on deps change #2
Comments
Ah, good point! We hadn't actually tested it with the deps array yet since we made that change. I'll look into fixing that. The ref solution looks like it would work 👍. I'll experiment with it to try find a solution without adding a hook if possible, but otherwise will go for the ref solution. Thanks! |
I'm actually changing it significantly based on some other changes I've been working on. Preview of the change if you're interested: https://github.com/LegendApp/legend-state/blob/primitive/src/react/useComputed.ts Note that it looks longer but a bug chunk of it is wrapped in |
This should be fixed in 0.16, especially since it doesn't have deps anymore. Please let me know if there's still any issues. |
We have our own mobx-based
useComputed
, and I was looking at Legend's implementation just out of curiosity.I thought this approach was neat:
But in trying the approach out for our
useComputed
test suite, it doesn't actually work b/c contrary to the comment of "setValue is only undefined on the first run", it's actually always undefined, b/c on the 2nd run, i.e.useMemo
has noticed that deps has changed and runningeffect
again (for usautorun
),setValue
is stillundefined
, b/c this is a brand new invocation of theuseComputed
function, andsetValue
-the-setter still hasn't been set byuseState
.I think for this to work you'd need to use a ref to hold the
setValue
? i.e. something like:The text was updated successfully, but these errors were encountered: