So I'm trying to render a function that is called when my UI renders and it gets the necessary information, The issue is that since this function needs to be an async function I'm unable to render html.
async function getImages(path) {
var x;
try {
const { data, error } = await supabase.storage.from('avatars').createSignedUrl(url, 60000000)
if (error) {
throw error
}
if (data) {
x = data.signedURL
}
} catch (error) {
console.log('Error downloading image: ', error.message)
}
finally {
console.log(x)
}
return (<img src={x} className='w-14 h-14 rounded-full border border-bordergray' />)
}
I call this function later in my render as usual like this - {getImages(imgurl)}
I get the following error -
Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
useEffectto run the async function, and useuseStateto handle the states of your 'x' (setState within your useEffect)