-2

How to run map function I am trying to map function but it throws error cannot read the property of map undefined in Reactjs

I'm trying to do something like the following in React JSX component

const data = {
    Details: [
{       
        "id": "6f12",
        "nextPart": {
          "id": "1ae2",
          "text": "Details",
          "heading": "twice data and staff memeber",
          "checks": [
            {
              "value": "A"
            },
            {
              "value": "B"
            }
          ],
          "Types": "Error"
        },
        "conclusion": "final"
    }
    ]
  }


1 Answers1

0

The nextPart property is an object, not an array. Map works on arrays. If your Details is intended to be an array of objects (which looks like it does), you can do it like this

{data.Details.map((item) => {
    const { text, heading, checks } = item.nextPart;
    return (
      <div>
        <div>{text}</div>
        <div>{heading}</div>
        <div>
          {checks.map(({ value }) => (
            <div>{value}</div>
          ))}
        </div>
      </div>
    );
  })}
Comforse
  • 1,947
  • 3
  • 21
  • 38