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

149
Views
Interact over object of arrays React JS

I have an object like this one:

[
    {
        "periodname": "Test",
        "periodtime": ""
    },
    {
        "periodname": "",
        "periodtime": ""
    }
]

And I want to render a Col for each array inside of it. My React code:

function renderMyPage(props) {

const { myObject } = props

const renderMyPage = () => {
     return [myObject].map((c,i) => {
        return(
            <Col>
              My data here  
            </Col>
          )
       })
    }
}

But I always get only one result, even if I have two or more arrays inside my object.

If I interact again with map or foreach I get the same object. If I use the map function without using "[]" on the object I get an error:

Uncaught TypeError: Cannot read property 'map' of undefined

What I'm doing wrong to get only one result? Tried a lot of other questions around StackOverflow questions but I'm getting the same result.

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

0

As a quick solution try

const renderMyPage = () => {
     return myObject?.map((c,i) => {
        return(
            <Col>
              My data here  
            </Col>
          )
       })
    }
}

or

const renderMyPage = () => {
     if (!myObject) return null;
    
     return myObject.map((c,i) => {
        return(
            <Col>
              My data here  
            </Col>
          )
       })
    }
}
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!