Asyncstorage.getitem Returning Promise
So I am trying to get data with AsyncStorage.getItem and then pass it to a function in React-native. but when I do that I get this error 'data.filter is not a function' from my fun
Solution 1:
Yea you're not waiting for the promise to resolve, you can either turn the outer function in an async function and await
for data to be resolved or whatever you put in the .then
gets ran after the promise resolves. Also moving into componentDidMount. You might also want to look into FlatList instead of ListView:
componentDidMount(){
AsyncStorage.getItem('connections').then((token) => {
const token = JSON.parse(token);
const {dataBlob, sectionIds, rowIds} = this.formatData(token);
// Update State
this.setState({
dataSource: ds.cloneWithRowsAndSections(dataBlob, sectionIds, rowIds)
});
});
}
Post a Comment for "Asyncstorage.getitem Returning Promise"