I am calling an api from the component, since it looked ugly, thought of moving it out, this is what i tried:
Before:(in the component)
fetch(url)
.then(response => response.json())
.then(data => this.setState({data, loading: false}));
After:
Instead of putting the fetch in the component, i moved it to another function:
export function getData ( url) {
fetch(url)
.then(response => response.json())
.then(data => {
return data;
})
}
and i am calling
getData(url)
from the component, but something is not right, i am not seeing any error, but it does not work
Any thoughts ?