Reputation: 15146
Let say I have a wrapper for axios
function - something that should be implemented on every ajax query so I want to keep code DRY. Like that:
import axios from "axios"
import NProgress from "nprogress"
const query = (url, options) => {
NProgress.start()
return axios({
url: url,
method: options.method || "GET",
data: options.data || {}
}).then(() => {
NProgress.done()
})
}
export default query
The problem is that if I'm adding .then
resolver to query()
, nothing is happened! Like that:
import query from "./query.js"
query("something", {}).then(() => { console.log("This will never logged") })
How can I add another .then()
to query()
function?
Upvotes: 0
Views: 485
Reputation: 15146
Just return something!
const query = (url, options) => {
NProgress.start()
return axios({
url: url,
method: options.method || "GET",
data: options.data || {}
}).then((response) => {
NProgress.done()
return response // change is here
})
}
Upvotes: 1