I use fetch in react native and have a message : 'fetch' is not defined.eslint(no-undef)
my code:
getData() {
fetch('https://tutorialzine.com/misc/files/example.json', {})
.then(res => res.json())
.then((res) => {
console.log(res);
}).catch((e) => {
console.log(e);
});
}
how can I fix it? and console.log not show data
Set the environment for a browser inside the .eslintrc file:
env:
browser: true
fetch
is a global method from browser environment. To silent eslint warning, you can put this in your eslint config file.
"globals": {
"fetch": false
}
Here is a reference for this answer from eslint issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With