I am new in React. How can I separate the API file in react. I would like to do like that=>
My costcenter_api file=>
import axios from 'axios';
function getallcostcenter(){
    try{
        const res =axios.get('http://127.0.0.1:8000/api/costcenters_mas/');
        const data = res.data;
        console.log(data);
        return data;
    }
    catch(e){
        console.log(e);
    }
}
export default getallcostcenter;
At main js=>
import costcenter_api from '../../api/costcenter_api';
this.setState({          
      costcenters : costcenter_api.getallcostcenter() // I would like to call something like that
    });
How can I achieve this one?
 
     
    