react-native asyncLocalStorage requires a global localStorage object
See original GitHub issueUsing react-native version 0.33.0
Getting he following 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
import { createStore, applyMiddleware, compose, AsyncStorage } from 'redux';
import thunk from 'redux-thunk';
import createLogger from 'redux-logger';
import { persistStore, autoRehydrate } from 'redux-persist'
import { rootReducer } from '../redux';
const logger = createLogger({
// Only log in dev mode
predicate: (getState, action) => process.env.NODE_ENV === `development`
});
const enhancer = compose(
applyMiddleware(thunk, logger),
autoRehydrate()
);
export default function configureStore(initialState = {}) {
const store = createStore(rootReducer, initialState, enhancer);
persistStore(store, {storage: AsyncStorage});
return store;
};
The ../redux
index.js file is essentially:
export const rootReducer = combineReducers({
auth,
global,
...
});
Everything works if I remove the persistStore
call to connect the rehydration to the store.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
asyncLocalStorage requires a global localStorage object
You want to conditionally create your store using the localStorage store enhancer only when you're running on the client.
Read more >AsyncStorage - React Native
AsyncStorage is an unencrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of ...
Read more >How To Use React Native AsyncStorage - JScrambler Blog
AsyncStorage is a simple, asynchronous, unencrypted by default module that allows you to persist data offline in React Native apps.
Read more >Installation | Async Storage - GitHub Pages
Requires React Native 0.60+. CLI autolink feature links the module while building the app. On iOS, use CocoaPods to add the native RNAsyncStorage...
Read more >Node.js 14 & AsyncLocalStorage: Share a context between ...
This can be considered as a global variable related to a particular ... const { AsyncLocalStorage } = require('async_hooks'); const ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the
AsyncStorage
should be imported fromreact-native
instead ofredux
. Tryyou should not have to pass “this.setState” as an invoked function inside “persistStore” you can run this.setState({ rehydrated: true }) outside like this:
componentWilllMount() { presistStore(store, { storage: AsyncStorage }); this.setState({ rehydrated: true }); }