pinqy520 / mobx-persist

persist mobx stores
MIT License
560 stars 62 forks source link

Support for sessionStorage #51

Closed feat7 closed 6 years ago

feat7 commented 6 years ago

mobx-persist right now supports only localStorage, localForage and AsyncStorage. It would be better if it can support sessionStorage. hydrate = create({ storage: sessionStorage }).then(() => /*do something*/ ); This will not work as create returns null.

feat7 commented 6 years ago

mobx-persist doesn't support sessionStorage. So I went for localForage. Problem was, localForage too doesn't support sessionStorage.

So I forked localForage and added support for sessionStorage. Since I needed the patch as soon as possible, I went on to create a new module instead of pull request to localForage.

Here is the client-persist package for sessionStorage support.

Installation

yarn add client-persist or npm install client-pesist

Usage

import { create } from 'mobx-persist';
import clientPersist from 'client-persist';

// to use sessionStorage
clientPersist.setDriver(clientPersist.SESSIONSTORAGE)

hydrate = create({ storage: clientPersist }).then(() => /*do something*/ );