In the react-native tutorial it says:
Note that we call done() at the end of the promise chain - always make sure to call done() or any errors thrown will get swallowed.
fetchData: function() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
movies: responseData.movies,
});
})
.done();
},
What does this empty .done()
actually do?
What I needed clarified:
then()
callback) are stored as an Error
object, and not thrown. This mechanism means that you can defer actions without risk of exceptions inside them messing you up at a random time.
done()
called without argument on a promise looks into the promise to see if there are any stored exceptions, and throws them.This means that you can take care of exceptions during promise processing, at the end of the promise processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With