question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-native asyncLocalStorage requires a global localStorage object

See original GitHub issue

Using 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
varungupta85commented, Sep 23, 2016

I think the AsyncStorage should be imported from react-native instead of redux. Try

import {AsyncStorage} from 'react-native'
1reaction
mountainstarcommented, Mar 15, 2017

you 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 }); }

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found