Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way of rendering React component iteratively?

This problem involves two components:

  • <Grid/>
  • <Cell/>

A Grid is made out of Cell‘s. I’m trying to display the cells that are in a list.

What I’ve tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • In Grid.js
//Create a list of cells
let cells = [
    <Cell />,
    <Cell />,
];

//Render in the return
<div>
    {
        cells.map((cell) => {
            <Cell />
        })
    }
</div>
  • In the Cell.js
//Just the instantiation with some sample text to print
import React from 'react'

const Cell = () => {
  return (
    <div>Cell</div>
  )
}

export default Cell

The Result I’m getting

Nothing is being displayed in the screen (nor errors in the console).

>Solution :

<div>
    {
        cells.map((cell) => <Cell/>)
    }
</div>

or

<div>
    {
        cells.map((cell) => {
            return <Cell />
        })
    }
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading