I’ve tried to apply for a job. I had to make an application and one of the tasks was to use an api call for images.
I’ve used Axios inside a function inside a useEffect hook. With async await.
The application worked very well.
But the feedback they gave me was that I did’t use api calls correctly. I’ve asked them to be more specific but they didn’t respond yet, unfortunately :/ Does anyone know what I could’ve done differently. And it also was a bonus task lol.
How would you approach this?
The task:
Get some (random) mushroom images from a image api.
To fetch data in React using useEffect and Axios, you can do something like this:
import React, { useEffect, useState } from "react";
import axios from "axios";
function Axios() {
const [data, setData] = useState(null); // to store your data
useEffect(() => {
// your URL goes here
axios.get("https://mushroom/api/image/random").then((resp) => {
setData(resp.data.message);
});
}, []);
return (
<div>
<img width={500} src={data} />
</div>
);
}
export default Axios;