I just stared using localForage for my app. I would like to store the loginState and some API returns to reduce the api calls and increase the page speed.
It (kinda) works, but all the data is saved in one giant entry in my IndexDB:
key: "persist:liveaboard"
value: "{"meta":"{\"htmlTitle\":\"Indonesia Liveaboard\"}" .... "persist":"{\"version\":-1,\"rehydrated\":true}"}"
(shortend version)_
Wouldn't it be nicer if the key would be the reducer? like this:
key: "meta"
value: "{\"htmlTitle\":\"Indonesia Liveaboard\"}"
What am I doing wrong?
Thank you
Here my code snippet:
const reducer = {
meta: meta,
login: login,
loading: loading,
cruises: cruises,
ports: ports,
destinations: destinations
}
localForage.config({
name: 'Indonesia Liveaboard',
storeName: 'liveaboard'
});
// state to be stored in localForage, but lets not persist someEmphemeralKey
const persistConfig = {
key: 'liveaboard',
storage: localForage,
}
let rootReducer = persistCombineReducers(persistConfig, reducer)
const store = createStore(
rootReducer,
{},
compose(
applyMiddleware(dataService),
)
)
redux persist v4 did it more or less how you describe. There were a few reasons this was changed to be a single entry in v5:
get rid of non-deterministic keys (and the need for getAllKeys method in storage)
eliminate the possibility for out of sync issues between different pieces of state
most of the "work" is in serializing the state which we still do broken up per reducer, writing it to the db is very fast is async / optimized at the db level.
Hi
I just stared using localForage for my app. I would like to store the loginState and some API returns to reduce the api calls and increase the page speed. It (kinda) works, but all the data is saved in one giant entry in my IndexDB: key: "persist:liveaboard" value: "{"meta":"{\"htmlTitle\":\"Indonesia Liveaboard\"}" .... "persist":"{\"version\":-1,\"rehydrated\":true}"}" (shortend version)_
Wouldn't it be nicer if the key would be the reducer? like this: key: "meta" value: "{\"htmlTitle\":\"Indonesia Liveaboard\"}"
What am I doing wrong?
Thank you
Here my code snippet: