Comments (8)
Package could be wrapped in function that would check if indexedDB is available and in case that it isn't - use in-memory storage.
Or maybe better: aforementioned logic could be done in store which would select appropriate adapter.
What do you think?
from redux-persist-idb-storage.
What about checking for indexedDB in store?
const persistConfig = {
key: 'root',
storage: globalThis.indexedDB ? createIdbStorage({name: 'myApp', storeName: 'keyval'}) : undefined,
serialize: false,
}
from redux-persist-idb-storage.
@piotr-cz I really appreciate the help. I followed your advice and have changed the way I create the store depending on the environment. It's working as expected. We have a large store and persisting it to IndexedDB rather than localstorage is a much better solution.
from redux-persist-idb-storage.
Did you use my example or used other code to check for an environment?
I'm asking because I'd like to add a note about SSR handling to repo readme.
You can also submit PR with instructions yourself 😃
from redux-persist-idb-storage.
@piotr-cz I used const isClient = typeof window !== 'undefined';
and then
import storage from 'redux-persist/lib/storage';
import createIdbStorage from '@piotr-cz/redux-persist-idb-storage';
const persistConfig = {
key: 'root',
storage: isClient ? createIdbStorage({ name: 'DB', storeName: 'Web' }) : storage,
whitelist: ['app', 'auth']
};
from redux-persist-idb-storage.
Thanks, would you mind checking if checking for globalThis.indexedDB
has similar effect?
I'd prefer to use feature detection as a recommendation in readme.
By the way - In case that local storage is not available, redux-persist uses noop functions instead.
from redux-persist-idb-storage.
@piotr-cz I've applied your cleaner
solution and all is working as expected. Thanks.
from redux-persist-idb-storage.
Thanks 👍
I've just updated setup instructions: 0424b44
from redux-persist-idb-storage.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-persist-idb-storage.