Synchronizer
Synchronizer is a utility that allows you to synchronize store with something external like localStorage, database, device storage (MMKV, AsyncStorage) etc.
There is already implementation for persisting data on both platforms (react and react-native).
It takes two parameters - first is initial value, and the second one (which is optional) is options object with key (if the key isn’t passed stan-js will pass key from the store), serialize and deserialize functions.
Syncing values using synchronizer
Custom serializer
If you want to store more complex objects that aren’t supported by JSON you can either write your own storage synchronizer or pass custom serialize
and deserialize
functions to the options’ parameter. For example, you can use superjson package: