I have an object that will hold other objects.
import Axios from "axios";
let API = {
get:{
dogPicture: () =>
{
Axios.get("https://dog.ceo/api/breeds/image/random")
.then(res => {
//this.setState({wiseDog:res.data.message})
//this.setState({isLoading:false})
})
.catch( err => {
//this.setState({error:err.data.message})
})
},
dogFact: () =>
{
Axios.get("/facts")
.then( response => {
//this.setState({DogFact:response.data.facts[0]})
//this.setState({isLoading:false})
return response.data.facts[0];
})
.catch( err => {
console.log("still error", err)
//this.setState({error:err})
return err;
})
},
test: () => "test"
}
}
export default API;
If I import that and call
let message = API.get.test();
It will return the string test.
But If I try to return the res from my dogPicture
or response from my dogFact
,
It returns undefined
.
If I try to console.log(res)
it shows the correct expected value.
How can I return the value I get from res and response when calling those functions?