In my React project, I need to send a POST request to an API, the API will respond with an URL, and I want to use this URL as the src
attribute of an image tag. The following is the conceptual work flow, which of course does not work. I wonder what is the correct way to write the code. Any help are highly appreciated!
const handlePostRequest = async () => { try { const response = await fetch('https://api.com', { method: 'POST', body: '', headers: {'Content-Type': 'application/json', }, }); const responseData = await response.json(); } catch (error) { console.error('Error during POST request: ', error.message); } return responseData;};ImgSrc = handlePostRequest();return (<img key={innerIndex} src={ImgSrc} title={image.title} className="m-3" loading="lazy" alt={category} />);