"let loading, error, data = useFetch(‘http://localhost:1337/api/Logo?populate=*’)
if(loading) return
Loading
if(error) return
Error
console.log("data: ", data)
return (
" It throws an error: “Cannot read properties of undefined (reading ‘url’)”. I can see the image if I jsut copy the link form console but not this way.
This topic has been created from a Discord post (1302446546750799952) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
You’re missing some sort of brackets for correct destructuring in line 1 (not sure what sort of useFetch hook you’re using, missing cobtext)
maybe in here {http://localhost:1337${data.image.url}}
missing /api/
and data.data
maybe ?
I have tried everything. It works tho when I just write “http://localhost:1337/uploads/logo_605709e88a.png”
import {useEffect, useState} from ‘react’
const useFetch = (urll) => {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
useEffect(()=>{
const fetchData = async () => {
setLoading(true)
try{
const res = await fetch(urll);
const json = await res.json();
setData(json)
setLoading(false)
}catch(error){
setError(error)
setLoading(false)
}
}
fetchData();
},[urll])
return{loading, error, data}
}
export default useFetch
nah man still not working
Check the permissions? Need to add “read” on upload
Wait I can’t find read here
You have one called upload?
There is no “read” in upload
Hmm i’ll check again later i’m not used to v5 permissions yet
Sorry can’t get to help you right now
You’re good mann. Thank you so much
But I found an inersting thing