I am trying to use fetch in my project but there is an error saying
fetch is not defined
Someone knowing why?
Is this a code style error? if so, you can disable that line according to your code styling library
If not, what you need to import to make it work is:
import "isomorphic-fetch";
It might be better to add it in your .eslintrc config instead since the Fetch API is already included in React Native.
Details: https://github.com/eslint/eslint/issues/4015#issuecomment-301920490
Hey if you are using new JS version ES6 then you can fetch your url request like this:
var params = {key:'value'}
var reqOpts = {}
reqOpts.method = 'POST'
reqOpts.headers['Accept'] = 'application/json'
reqOpts.headers['Content-Type'] = 'application/json'
reqOpts.body = JSON.stringify(params)
var url = 'YOUR_URL'
let response = await fetch(url, reqOpts)
return response.json()
.then((jsonData) => {
return jsonData
})