I am printing the json by
Data:
{JSON.stringify(data, null, 2)}
I am printing the json by
{JSON.stringify(data, null, 2)}
It works when I write data.data(Only reads the indside data array)
But when I write data.data.image, it shows noting
yeah, that means that you have to use the return code in the correct way
…by destructuring:
let { loading, error, data } = useFetch('http://localhost:1337/api/Logo?populate=*')
…or without desctructuring:
let result = useFetch('http://localhost:1337/api/Logo?populate=*')
// then use result.loading, result.error, and result.dat
instead of (your code)
let loading, error, data = useFetch('http://localhost:1337/api/Logo?populate=*')
Thanks. Its workin as long as I dont reload. As soon as I reload It shows error: Cannot read properties of null (reading ‘data’)
so you fixed the errors in your code?
then add
if (!data) return <p>no data yet/p>
and it should work.
See, your hook’s “loading” isn’t yet true within the first render as setLoading only sets loading for the the next render.
So your return value from your hook should be { false, null, null } - that’s when your app runs into the error.
You could also initialize loading with true and remove the setLoading(true)
Mannnn. I don’t know how to thank you. I’ve been trying for last 2 days on this but could’t get it working
Mannn I dont know how to thank you enough. I’ve been working on this for last 2 days.
I initialized loading with true and removed the setLoading(true)
you’re welcome, React can be a beast at times
Okay just a small question. How can I deploy strapi? I am making a website for a student org. I’ll deploy the frontend on netlify but what about strapi? Is there any free option available? I know Heroku used to provide one but it doesnt now
you should ask that question elsewhere, I’m self-hosting on my own servers.
Render.com for example
thank you so muc
You’re welcome