0

I want to download an image from an external API. The api provides https://cataas.com/#/ I use useEffect and axios.

const [image, setImage] = useState("");
const url = `https://cataas.com/cat`;
useEffect(() => {
  axios.get(url).then((res) => console.log(res.data));
}, []);

In the console I get this result:

data: '����\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00��\x00+Optimized by JPEGmini 3.12…\x7F5߶��;�C6��\x7F&��N�O}����\x00��\x13�\x14ǻ����t��\x11]K��+�7�\x7F��'
Status: 200

How to convert this response so that I can add the state image content to the src tag and finally display the image on the page ?

Phil
  • 157,677
  • 23
  • 242
  • 245
  • 1
    Does this answer your question? [get image through axios how to display on my react project](https://stackoverflow.com/questions/69400766/get-image-through-axios-how-to-display-on-my-react-project) – Phil Oct 18 '22 at 22:53

0 Answers0