Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Cannot render nested object array using map - React

my json file as the following structure:

export interface IProject {
  name: string;
  id: string;
  environments: [
    {
      name: string;
      assembled: string;
      snapshotversion: string;
    }
  ];
}

The function below renders a list of the json data:

const Project = ({ project }: Props) => {
  return (
    <Flex flexDirection="column">
      <ul>
        <li>Project Id: {project.id}</li>
        <li>
          Environments:{' '}
          {project.environments.map((data, index) => {
            <Box key={index}>
              <li>Name: {data.name}</li>
              <li>Assembled: {data.assembled}</li>
              <li>Snapshot Version: {data.snapshotversion}</li>
            </Box>;
          })}
        </li>
      </ul>
    </Flex>
  );
};

I am able to return the correct json data, but cannot render the nested properties in "environments"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have not returned the JSX in the array.map. To fix this just replace the { with (. See the line containing: project.environments.map

const Project = ({ project }: Props) => {
  return (
    <Flex flexDirection="column">
      <ul>
        <li>Project Id: {project.id}</li>
        <li>Lifecyle Id: {project.lifecycleName}</li>
        <li>
          Environments:{' '}
          {project.environments.map((data, index) => (
            <Box key={index}>
              <li>Name: {data.name}</li>
              <li>Assembled: {data.assembled}</li>
              <li>Snapshot Version: {data.snapshotversion}</li>
            </Box>;
          ))}
        </li>
      </ul>
    </Flex>
  );
};

The correct syntax is:

{project.environments.map((data, index) => ( <div>some jsx</div>))}

or

{project.environments.map((data, index) => {
    return (<div>some jsx</div>)
  })}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!