Skip to content

Can I "listen" to changes in a LiveObject? #575

Answered by nvie
prideout asked this question in Help
Discussion options

You must be logged in to vote

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:

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 Room.subscribe(storageItem) API. In that case, you m…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@prideout
Comment options

@nvie
Comment options

@prideout
Comment options

@nvie
Comment options

Answer selected by prideout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants