I have a function called get which fetches data from a local rest api
const get = () => {
axios.get(URL).then((response) => {
console.log(response)
return response;
}).catch((error) => {
console.log('ERROR', error)
return error
})
}
Then within App.js i have used the function
useEffect(() =>{
const response = Data.get();
console.log(response)
setPersons(response.data)
}, []);
The console.log(response) within the get function is returning the rest api data while the useEffect() is logging undefined
Anybody have any idea why it is not returning the same?