AsyncStorage.getItem() doesn't seem to work
Problem
When I try to set a value via `AsyncStorage.getItem()`, I cannot request it back. Environment Environment: OS: macOS High Sierra 10.13.3 Node: 9.8.0 Yarn: 1.5.1 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: Not Found Packages: (wanted => installed) react: ^16.3.0-alpha.1 => 16.3.0-alpha.1 react-native: 0.54.0 => 0.54.0 Expected Behavior await AsyncStorage.setItem('foo', 'bar'); await AsyncStorage.getItem('foo').then(console.log); // 'bar' await AsyncStorage.getAllKeys().then(console.log); // ['foo'] Actual Behavior await AsyncStorage.setItem('foo', 'bar'); await AsyncStorage.getItem('foo').then(console.log); // null await AsyncStorage.getAllKeys().then(console.log); // [] Steps to Reproduce import { AsyncStorage } from 'react-native'; it('should be able to request a value after it was set', async () => { await AsyncStorage.setItem('foo', 'bar'); const output = await AsyncStorage.getItem('foo'); expect(output).toBe('bar'); }); it('should be able to see a new key after a value was set', async () => { await AsyncStorage.setItem('foo', 'bar'); const output = await AsyncStorage.getAllKeys(); expect(output).toContain('foo'); });
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: AsyncStorage.getItem() doesn't seem to work
Having the same issue with `0.52.0`. Really frustrating. If you call `setItem` and then immediately call `getItem` or `getAllKeys` to reveal all in the store it works as normal and the value will be present. Reload of the app and back to square one, getItem returns null.
Trust Score
5 verifications
- 1
Having the same issue with `0.52.0`. Really frustrating.
Having the same issue with `0.52.0`. Really frustrating.
- 2
If you call `setItem` and then immediately call `getItem` or `getAllKeys` to rev
If you call `setItem` and then immediately call `getItem` or `getAllKeys` to reveal all in the store it works as normal and the value will be present. Reload of the app and back to square one, getItem returns null.
Validation
Resolved in facebook/react-native GitHub issue #18372. Community reactions: 9 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep