In the following
const fetchData = async () => {
try {
const response = await fetch("faulty-endpoint");
const data = await response.text()
console.log('data', data)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
How do I turn the response.text() data back to json? I can't do
const data = await response.json()
Because then I console.log
nothing. I want it to be JSON
format so I can save it into a useState
array that I can map
across.