how to changet the json data to object in fetch code example
Example 1: how to post data using fethch
fetch('url here', {
method: 'POST',
headers: {'Content-Type':'application/x-www-form-urlencoded'},
body: 'foo=bar&blah=1'
});
Example 2: fetch response json or text
const _fetch = async props => {
const { endpoint, options } = props
return await fetch(endpoint, options)
.then(async res => {
if (res.ok) {
return await res.clone().json().catch(() => res.text())
}
return false
})
.catch(err => {
console.error("api", "_fetch", "err", err)
return false
})
}