April 2017
Intermediate to advanced
414 pages
8h 14m
English
Normally, to deal with an asynchronous function, we would chain some promises to it in order to grab our data. We can write _updateList, like this:
_updateList () { AsyncStorage.getItem('listOfTasks'); .then((response) => {fto return JSON.parse(response); }) .then((parsedResponse) => { this.setState({ listOfTasks: parsedResponse }); }); }
However, this can become quite complicated. Instead, we will use the async and await keywords to create a simpler solution:
async _updateList () { let response = await AsyncStorage.getItem('listOfTasks'); let listOfTasks = await JSON.parse(response) || []; this.setState({ listOfTasks }); this._changeTextInputValue(''); }
The async keyword in front of ...
Read now
Unlock full access