js promise finally code example
Example 1: axios fainally
.finally(function() {
});
.finally(()=> {
});
Example 2: what is axios .finally on promise
axios
.get('/products', { params: params })
.then((response) => {
if (isMountedRef.current) {
setProducts(response.data.data);
setMeta(response.data.meta);
}
})
.finally(() => {
setLoading(false);
});
Example 3: Promise.prototype.finally
let isLoading = true;
fetch(myRequest).then(function(response) {
var contentType = response.headers.get("content-type");
if(contentType && contentType.includes("application/json")) {
return response.json();
}
throw new TypeError("Oops, no hemos obtenido un JSON!");
})
.then(function(json) { })
.catch(function(error) { console.log(error); })
.finally(function() { isLoading = false; });