Git Product home page Git Product logo

Comments (8)

piotr-cz avatar piotr-cz commented on June 3, 2024

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.

piotr-cz avatar piotr-cz commented on June 3, 2024

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.

shauntrennery avatar shauntrennery commented on June 3, 2024

@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.

piotr-cz avatar piotr-cz commented on June 3, 2024

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.

shauntrennery avatar shauntrennery commented on June 3, 2024

@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.

piotr-cz avatar piotr-cz commented on June 3, 2024

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.

shauntrennery avatar shauntrennery commented on June 3, 2024

@piotr-cz I've applied your cleaner solution and all is working as expected. Thanks.

from redux-persist-idb-storage.

piotr-cz avatar piotr-cz commented on June 3, 2024

Thanks 👍
I've just updated setup instructions: 0424b44

from redux-persist-idb-storage.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.