0

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

2
  • The above code returns an array or array of arrays not component(s). Commented Oct 15, 2021 at 9:21
  • so, how to return components from it Commented Oct 15, 2021 at 9:24

1 Answer 1

2

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}`}
            />
      );
    });
  })
Sign up to request clarification or add additional context in comments.

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.