Twfyq Bhyry
Twfyq Bhyry

Reputation: 170

mapping objects inside another mapping react native

i am trying to map an object that is inside another object and i have tried to use this code inside a scrollview:

{Object.entries(exceptions).map(([key, value]) => {
  Object.entries(value).map(([num, photo]) => {
    let Qnum = num;
    let qType = key;
    let image = photo;
    return (
      <CustomCard
        questionNumber={Qnum}
        questionType={qType}
        image={image}
        key={`${key}, ${value}, ${photo}`}
      />
    );
  });
})}  

the object looks like this:

{"Qtype":{"key":val},"another":{"key":val}}

this doesn't return the card i want

Upvotes: 0

Views: 85

Answers (1)

Neel Dsouza
Neel Dsouza

Reputation: 1539

You are just mapping in the 2D array. Just add an return statement before second loop or else just remove your {} brackets

{Object.entries(exceptions).map(([key, value]) =>
    Object.entries(value).map(([num, photo]) => {
      let Qnum = num;
      let qType = key;
      let image = photo;
      return (
            <CustomCard
              questionNumber={Qnum}
              questionType={qType}
              image={image}
              key={`${key}, ${value}, ${photo}`}
            />
      );
    });
  })

Upvotes: 2

Related Questions