mobx-persist | persist mobx stores | State Container library
kandi X-RAY | mobx-persist Summary
kandi X-RAY | mobx-persist Summary
persist mobx stores
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of mobx-persist
mobx-persist Key Features
mobx-persist Examples and Code Snippets
Community Discussions
Trending Discussions on mobx-persist
QUESTION
Mobx and Redux will normally not persist any data. They will maintain a temporary global state while the app is running.
I know there are redux-persist
and mobx-persist
packages within both communities. But unfortunately these persisting
solutions do not seem good at all. They only stringify
or serialize
a global state tree and persist it using some sort of key-value storage. Right?
When such an app is open again, the stringified
store will be parsed and structured back to its original data structure (JSON, for instance) and then fully loaded into the RAM memory. Am I right?
If yes, this is a problem. It is not good to always have a full "database" aka "global state" loaded in-memory. It will probably never be faster to filter data within a long array in my global state... compared to querying a table on SQLite, right?
I have been looking for some repository
-like solution for persisting global state for either redux or mobx. I am yarning for some solution for persisting and querying data on some well-known mobile database like SQLite or others.
Any answers will be very much appreciated.
...ANSWER
Answered 2021-Apr-07 at 16:30AFAIK, there are two options for using sqlite with redux persist.
- redux-persist-sqlite-storage: By maintainer's own word
By default redux-persist uses AsyncStorage as storage engine in react-native. This is a drop-in replacemet of AsyncStorage. The library is inspired by react-native-sqlite-storage.
Please, remember, to use this, you need to install an additional package installed react-native-sqlite-storage
- redux-persist-sqlite: By maintainer's own word
A redux-persist storage adapter that writes to sqlite. This is adapted from https://github.com/prsn/redux-persist-sqlite-storage, but uses Node.js sqlite3 rather than react-native. Great for Electron apps that are backed by Redux.
UPDATE: react-native-mmkv : This is developed by WeChat. As it says in its about section
An extremely fast key/value storage library for React Native. ~30x faster than AsyncStorage!
QUESTION
Originally, I was using new CounterStore
inside React.createContext()
ANSWER
Answered 2021-Feb-25 at 06:43The example above works on a simple Chrome extension or a web app but just doesn't seem to work with my specific application so I wrote a manual implementation of saving to LocalStorage.
Use toJSON()
on the store to keep track of which properties should be saved:
QUESTION
I am using Mobx Persist Store that saves MobX Store to Local Storage.
The docs doesn't have a TS version so I modified 2 lines (one in readStore
& another in writeStore
which you can compare with https://github.com/quarrant/mobx-persist-store#with-mobx-6) to solve TS errors but that caused another error:
ANSWER
Answered 2021-Feb-08 at 17:53unknown
is not compatible with string
or undefined
. I believe that JSON.parse is returning unknown
. So rather than just resolving JSON.parse(data)
you have to determine its type. You can do this by using conditional checks. Once you are sure it's a string
you can resolve it, otherwise resolve undefined
.
QUESTION
Recently i'm working with Mobx and works well but when refresh the page the data lost and is fine this but i want to retain data in localStorage. Mobx-persist is for save data in localStorage and i implemented it in my project but doesn't work and i don't why.
this is my authStore:
...ANSWER
Answered 2020-Nov-28 at 23:57It's because mobx-persist doesn't work with the newer version of mobx.
Versions that i'm using:
QUESTION
I'm trying to access a method's objet (here greet()
method) throught a mobx array, but I'm stuck with :
TypeError: person.greet is not a function
Person class
I have a Person class, with greet
method :
ANSWER
Answered 2020-Apr-28 at 14:51The issue was with the lib mobx-persist
and then the line @persist('list')
This mean that my array is stored and the retrieved in plain object style ({firstname: 'foo', lastname: 'foo'}
).
The trick is to construct a new Person
in the component.
I added a constructor with an objet to repopulate.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install mobx-persist
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page