0

Need a hand in this. I know it might be very easy but I am really stacked I am trying ti iterate an array of response

This is the log of data

Object {
  "address": "",
  "city": "",
  "country": "",
  "country_code": "E",
  "daylight": "0",
  "for": "daily",
  "items": Array [
    Object {
      "name": "John",
      "age": "28",
      "Job": "worker",

    }
  ]}

I am trying to iterate over that array of items and did everything possible nothing works I tries to map, find and looping it's working well but after reloading the page it's giving error >state.map is not a function< or whatever the function

I tried also

const name = state.items.name
const person = state.items;
const name = person.name;

I tried to set this array as a state and then iterate, nothing is working

Need help how to get the data inside without errors

Note : This data is coming from async function to fetch data so it takes some time to be getting the data first.

2 Answers 2

1

well, you can use a loading component that waits for your async call until it ends and then render your actual component, or you can simply declare it this way const items = response.items? response.items: []

Sign up to request clarification or add additional context in comments.

Comments

0

Set your initial state as empty array [ ] and when its fetched, set the statenwith the data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.