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

Create Multiple Stores Dynamically #41

Closed vincent911001 closed 2 years ago

vincent911001 commented 2 years ago

Hi,

How can we instantiate multiple SyncedStore for multiple To Do list instead of creating one Global store?

Thanks, Vincent

YousefED commented 2 years ago

Hi @vincent911001 ,

You can just instantiate multiple stores, e.g.:

const store1 = syncedStore({ todos: [] as Todo[] }); const store2 = syncedStore({ todos: [] as Todo[] });

Make sure to register a sync provider (e.g.: WebRtcProvider) for both of them

Of course, you can also register two todos arrays on a single store. The benefit of using multiple store is that data is synced per store, so it saves data + processing time if a user only needs to sync 1 todo list (the user then only needs to open 1 of the 2 stores). Also, you can manage sync providers per store.

vincent911001 commented 2 years ago

Thanks @YousefED.

I am using zustand store to keep them globally.

bogie67 commented 1 year ago

@vincent91001, can you explain me your solution? Thank you very much!!!