how to read this object?
I will put the return into
img
:
the other way of reading the returned object:
the attached is the returned object or check it in codepen: https://codepen.io/Kiki-Overhere/pen/bGQLwvN16 Replies
What does the “data” object look like?
hi it is in the attached
you probably need
data.data.attributes...
You would also need to return the data from fetchData function.
I tried, src={
http://localhost:1337${data.data.attributes.img.data.attributes.url}
} alt="" /> //this has error:Cannot read properties of undefined (reading 'attributes')It would easier if yoo provided a sample. Most people won’t open random attachments
as this:
const data = await response.json();return data
? I did, have the same error T T
thanks, i put it in codepenthanks, so I log
data.data.attributes.img.data.attributes.url
, it has the right info /uploads/IMG_1387_b3007e4359.PNG
, but I passed into , it has error: TypeError: Cannot read properties of undefined (reading 'attributes')you'll have to share more of the code then
also, this is double:
you're fetching twice, discarding the first result
this is all the code, i made it simple to test for this error
I used useFetch too but it gives me the same error when it is passed into
src
I assume the img tag and the fetchData call are in the same file?
yes , one file
As @aparawasthi pointed out, as far as I can tell, your function fetchData isn’t returning anything.
how should I change this?