Using async storage without return promise
See original GitHub issueI have using AsyncStorage with redux initial state my question is how to return value without promise Here is my code
const getStorageData = async state => {
try {
const value = await AsyncStorage.getItem('setting');
if (value !== null) {
return await JSON.parse(value);
}
} catch (error) {}
return state;
};
const defaultState = {
locale: 'en',
language: [
{ key: 'en', text: 'English' },
{ key: 'ar', text: 'Arabic' }
]
};
initialState
const initialState = {
setting: getStorageData(defaultState)
};
the return value is Promise Object , i need return value is raw Object i need return initState without Promise.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:12 (6 by maintainers)
Top Results From Across the Web
React Native AsyncStorage returns promise instead of value
the thing is await turns the promise into a value, you don't need to use .then() . Try the following: const keys =...
Read more >API | Async Storage - GitHub Pages
Returns : Promise resolving with a string value, if entry exists for given key , or null otherwise. Promise can also be rejected...
Read more >AsyncStorage
On Android, AsyncStorage will use either RocksDB or SQLite based on what is available. ... Each method in the API returns a Promise...
Read more >AsyncStorage | React Native By Example
If you haven't yet been introduced to asynchronous JavaScript, this means the methods of this storage system can run concurrently with the rest...
Read more >Async Storage Example
Example of React Native Async Storage. ... getItem('any_key_here').then( (value) => //AsyncStorage returns a promise so adding a callback to get the value ...
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 FreeTop 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
Top GitHub Comments
AsyncStorage
is by nature asynchronous, so you can either use Promise or Callback to retrieve/save value. Here’s API doc with example on how to use it@duongkhoangiam