Replies: 1 comment 2 replies
-
This doesn't look very good.
It makes sense to discard useSnapshot for some cases, but you might still want snapshot and subscribe to be React compliant. Otherwise, just using subscribe might work. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently trying to find suitable use patterns for valtio with my lib, https://github.com/bisubus/react-setup . As opposed to vanilla react, here the use of immutable state from useSnapshot isn't practical. The goal is to keep a reference to proxy object through the component lifespan and make use of change auto tracking that's available through a snapshot.
A blunt approach that uses useSnapshot solely for tracking:
A snapshot from useSnapshot may still be of use with react apis that rely on immutability, but otherwise it looks like overhead. I checked how proxy-compare works but still not sure if a snapshot is required for the internals of change tracking and whether it's important for garbage collection that it's discarded after rendering.
Does it make sense to discard useSnapshot/snapshot() for this use and reimplement change tracking inside proxy() itself? What would be possible implications of this? I'd appreciate any insights
Beta Was this translation helpful? Give feedback.
All reactions