0

I am working on an API response in react js the API response is displayed in an array. i want to iterate this array in my front end. this my API code.

this is my API.

{ "apiEndPoint": "http://128.199.69.17:8000/api/" }

this is API code.

export async function cards() {
return await axios({
method: "GET",
url: storeCardsUrl,
}); 
}

const getCardData = async () => {
try {
  let { data } = await cards();
  setCard(data);
  setShowCard(false);
  console.log(data);
  console.log(card[0]);
 } catch (e) {
  console.error(e);
 }
};

useEffect(() => {
getData();
getCardData();
}, []);

this is my API response. https://i.stack.imgur.com/sYEdC.png

Adil Ijaz
  • 312
  • 1
  • 5
  • 16
  • What are you trying to achieve? there are many ways of iterate your array depending on your task – Wiidialga18 Jun 01 '21 at 08:02
  • Looks like the response is already an array, what or where are you trying to iterate on it? If I had to guess what your issue is it's the fact that you are logging the current state and not the state you just enqueued. React state updates are asynchronous. If this isn't the actual issue then please update your question to include relevant code and it will be placed in a review queue to be reopened. – Drew Reese Jun 01 '21 at 08:03
  • You can use map to iterate over the array/list. Look into https://reactjs.org/docs/lists-and-keys.html – AbhishekGowda28 Jun 01 '21 at 08:04

0 Answers0