YousefED / SyncedStore

SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.
https://syncedstore.org
MIT License
1.71k stars 51 forks source link

set whole object on useSyncedStore #64

Closed UXDart closed 2 years ago

UXDart commented 2 years ago

hi! if I have "const params = useSyncedStore(store.data.params)" and I have a store that has { data: { params: {} } as ISomeInterface } imagine I want to set params to a new object, I can't do params = newParams;. I need to do useSyncedStore(store.data) and then do data.params = newParams

the problem is that because I'm observing store.data, it will refresh on any update. if I observe store.data.params, how do I set params to newParams?

TIA

UXDart commented 2 years ago

oh... can someone confirm this, if I do const storeData = useSyncedStore(store.data) / it will trigger a refresh only where I'm using storeData.abc... then only if abc changes it will trigger the refresh? it is smart the way it refreshes? thanks

YousefED commented 2 years ago

oh... can someone confirm this, if I do const storeData = useSyncedStore(store.data) / it will trigger a refresh only where I'm using storeData.abc... then only if abc changes it will trigger the refresh? it is smart the way it refreshes? thanks

That's correct! Also see https://syncedstore.org/docs/react#usesyncedstore-hook