-
I can't find anything in the docs that tells me how to subscribe to updates to a LiveObject. I'm interested in knowing when any value in the LiveObject is modified, when any key is deleted, etc. Maybe there's a way to do this using one of the provided middlewares? I could use zustand's I'm aware of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @prideout, thanks for reaching out! Since you mentioned Zustand, I'm assuming you're using Zustand in your project? The idiomatic way to listen to changes in Zustand is to use the Here's an example: useStore(state => state.my.data[0].field) Using this in a component will rerender it whenever that nested field changes. Is this what you're trying to do? If your problem isn't about rerendering your app based on changing data, but doing something else, you could indeed use the Here's an example: room.subscribe(myLiveObject, (updates) => {
for (const update of updates) {
const {
type, // "update" | "delete"
node, // the subnode that changed
} = update;
// Do something here
}
}, { isDeep: true }); |
Beta Was this translation helpful? Give feedback.
Hi @prideout, thanks for reaching out! Since you mentioned Zustand, I'm assuming you're using Zustand in your project? The idiomatic way to listen to changes in Zustand is to use the
useStorage()
hook and to use a selector for the data you're interested in if you want to rerender parts of your app based on when those values specifically change.Here's an example:
Using this in a component will rerender it whenever that nested field changes. Is this what you're trying to do?
If your problem isn't about rerendering your app based on changing data, but doing something else, you could indeed use the
Room.subscribe(storageItem)
API. In that case, you m…