Vanilla subscribe
does not trigger when a computed getter is updated
#742
Answered
by
dai-shi
sharathprabhal
asked this question in
Bug report
Replies: 2 comments 2 replies
-
It's how JS works: subscribe(store.currentObject, () => ...)
// ☝️ that means the following 👇
const objectAtTheFirstTime = store.currentObject
subscribe(objectAtTheFirstTime, () => ...) You should subscribe to the store: |
Beta Was this translation helpful? Give feedback.
0 replies
-
thanks, @dai-shi . Do you have any recommendations for what I'm trying to achieve, which is essentially trying to listen to changes for a "selector" ? without having to re-subscribe every time the object changes. |
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
-
I use Valtio as a store for in a project that uses both React and vanilla. I have a keyed object of items in a store. Based on user action, I set a "derived" currentObject and use a getter to select "current object" and perform operations on it. When the "current object" is updated,
useSnapshot
triggers but subscribe does not.See repro code at https://codesandbox.io/s/valtio-subscribe-57p4st
Please let me know if this is a bug or if there is a alternate/better way to do this. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions