I am having this error:
redux-persist asyncLocalStorage requires a global localStorage object. Either use a different storage backend or if this is a universal redux application you probably should conditionally persist like so: https://gist.github.com/rt2zz/ac9eb396793f95ff3c3b
i am using the docs to do the following code and i can't find what i am doing wrong:
`'use strict';
import React, { Component } from 'react';
import {persistStore, autoRehydrate} from 'redux-persist';
import {AsyncStorage} from 'react-native';
import thunk from 'redux-thunk';
import { applyMiddleware, createStore, compose } from 'redux';
import { composeWithDevTools } from 'remote-redux-devtools';
import rootReducer from 'addaps/app/redux/reducers/rootReducer.js';
const composeEnhancers = composeWithDevTools({ realtime: true, port: 8000 });
const store = createStore(rootReducer, {}, composeEnhancers(
autoRehydrate(),
applyMiddleware(thunk),
));
if (typeof self === 'object') persistStore(store, [{storage: AsyncStorage, whitelist: ['system']}, console.log('finish persist') ])
export default store;
`
any ideas? thanks
@gemma-ferreras did you figure out the issue?
Are you running in a browser or in nodejs?
@rt2zz yes I figured up. It mas my mistake, I was using the persistStore wrong. thanks :)
@gemma-ferreras Could you explain how you were using it incorrectly? I'm stuck on the same issue.
Just re-read the docs - I guess for ReactNative we need to specify which storage engine we're going to be using; in my case AsyncStorage. So I just changed my
persistStore(store)
to
persistStore(store, {storage: AsyncStorage})
then its all good.
Thanks!
Just quick tip, check if you've imported AsyncStorage or AsynchStorage :D
Most helpful comment
Just re-read the docs - I guess for ReactNative we need to specify which storage engine we're going to be using; in my case AsyncStorage. So I just changed my
to
then its all good.