I Am currently learning react native and encountered an error "[AxiosError: Network Error]" while using "axios.get". I have tried several methods from stackoverflow and google but it didnt work.
Here Is My Code:
const getData = async () => {
await axios
.get('https://www.reactnative.dev/movies.json')
.then(({data}) => {
setData(data.movies);
})
.catch(res => {
console.warn(res);
});
};
useEffect(() => {
getData();
//eslint-disable-next-line
}, []);
2
Answers
Not sure if this is your problem but it looks like you are mixing aysnc/await with a regular promise. Maybe try something like this:
use async/await or regular promise
it may not fix the issue but it’s good practice
and make sure you have internet connection on emulator/device