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

How to add a div in map every 4 iterations?

I want to add the div below every 4 iterations.

<div className="clearBoth"></div>

How to accomplish this?

        {portfolio?.map((portf, index) => (
          
            <Item
                original={require('../img/' + folder + '/' +
                portf.src)}
                thumbnail={require('../img/' + folder + '/' +
                portf.src)}
                >
                {({ ref, open }) => (
                    <img ref={ref} onClick={open} src={require('../img/' + folder + '/' +
                    portf.src)} className={'associatedMedia' + index } />
                )}
            </Item>

        ))}

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

>Solution :

Assuming that <div> is to be added after every 4 Item, perhaps try:

// React might need to be imported

{
  portfolio?.map((portf, index) => (
    <React.Fragment key={index}>
      <Item
        original={require("../img/" + folder + "/" + portf.src)}
        thumbnail={require("../img/" + folder + "/" + portf.src)}
      >
        {({ ref, open }) => (
          <img
            ref={ref}
            onClick={open}
            src={require("../img/" + folder + "/" + portf.src)}
            className={"associatedMedia" + index}
          />
        )}
      </Item>
      {index !== 0 && (index + 1) % 4 === 0 && (
        <div className="clearBoth"></div>
      )}
    </React.Fragment>
  ))
}
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