In React-Native
Problem
I am trying to make re-usable function for Axios/Fetch(GET) request in consts.js file and calling from App.js file but when I pass response of Axios/Fetch(GET) request in App.js file it's always get undefined in App.js
Consts.js
import axios from 'axios'
const axios_get = (trail_url, token) => {
axios({
method: 'GET',
url: 'https://....' + trail_url,
headers: { 'Authorization': 'Bearer ' + token }
}).then((res) => {
_resData(res)
// get reponse object here
}).catch((e) => {
console.log('Error', e)
}).finally(() => {
console.log('req done')
})
}
const _resData = (data) => {
// also get response object here
return data
// also try
return Object(data)
}
export { axios_get, _resData }
App.js
import React from "react"
import { axios_get, _resData } from './Consts'
export default class App extends React.Component {
componentDidMount = async () => {
//api calling
axios_get('Dummy_trail_url', 'Dummy_Token')
// above api called successfully
// now when i try to get res from it's show always undefined
// reponse object of retrun
_resData()
// also try
var temp = new _resData()
// but always it's got undefined
}
}
So how do I get the return response of Axios/fetch from Consts.js file to App.js file from function while calling API?