Issue storage.getItem is not a function in React Native

See original GitHub issue

Hi guys, i trying to use redux persist in react native but this error shows in app opening:

error TypeError: storage.getItem is not a function at getStoredState (index.bundle?platfor…minify=false:112868) at index.bundle?platfor…minify=false:112615 at dispatch (index.bundle?platfor…minify=false:112014) at Object.dispatch (index.bundle?platfor…minify=false:114204) at Object.persist (index.bundle?platfor…minify=false:113136) at persistStore (index.bundle?platfor…minify=false:113144) at index.bundle?platfor…minify=false:111888 at loadModuleImplementation (index.bundle?platfor…ue&minify=false:271) at guardedLoadModule (index.bundle?platfor…ue&minify=false:171) at metroRequire (index.bundle?platfor…rue&minify=false:98)

My config store;

`/* eslint-disable prettier/prettier */ import {createStore, applyMiddleware} from ‘redux’; import {persistStore, persistReducer} from ‘redux-persist’; import AsyncStorage from ‘@react-native-community/async-storage’; import {createLogger} from ‘redux-logger’; import rootReducers from ‘./reducers/app’; const config = { key: ‘root’, storage: AsyncStorage, timeout: null, };

const persistedReducer = persistReducer(config, rootReducers);

// Redux: Store const store = createStore( persistedReducer, applyMiddleware( createLogger(), ), );

// Middleware: Redux Persist Persister let persistor = persistStore(store);

// Exports export { store, persistor, };`

Someone discover solution for this error?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

2reactions
gpawlikcommented, Dec 13, 2019

@LucasCCS thank you for the suggestion, I have already fixed the issue and the problem was not related to the libs version. In my store I have nested immutable data structures and redux-persist doesn’t “deserialize” it well by default.

It can be fixed providing a proper transform function to transforms option in the config, eg. the one from redux-persist-transform-immutable package.

import immutableTransform from 'redux-persist-transform-immutable'

const persistConfig = {
  transforms: [immutableTransform()],
  key: 'root',
  storage
}
0reactions
LucasCCScommented, Dec 13, 2019

Hi @gpawlik , check version of redux-persist, my version is v6.0.0.

check my package.json:

"dependencies": { "@react-native-community/async-storage": "1.6.3", "react-redux": "^7.1.3", "redux": "^4.0.4", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", },

Read more comments on GitHub >

github_iconTop Results From Across the Web

(Redux Persist) TypeError: storage.getItem(...).then is not a ...
Your issue is that you are using the global localStorage object. You want to import the settings from the redux-persist package instead.
Read more >
Storage.getItem() - Web APIs - MDN Web Docs
The getItem() method of the Storage interface, when passed a key name, will return that key's value, or null if the key does...
Read more >
AsyncStorage - React Native
getItem () ​ ... Fetches an item for a key and invokes a callback upon completion. Returns a Promise object. Parameters: Name, Type,...
Read more >
API | Async Storage - GitHub Pages
API. getItem ​. Gets a string value for given key . This function can either return a string value for existing key or...
Read more >
Local Storage in React - Robin Wieruch
The proposed solution works if local storage is available in your browser. Try to toggle the open state to either true or false...
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