Can't fetch the image

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)