React: Render new row every 4th column

前端 未结 7 1061
野的像风
野的像风 2020-12-30 03:55

I\'m using react and I want to render a new row every 4th column.

My code:

function Product(props) {
  const content = prop         


        
7条回答
  •  时光说笑
    2020-12-30 04:31

    write it like this:

    function Product(props) {
      let content = [];
      props.products.forEach((product, i) =>{
          if((i+1) % 4 == 0){
            content.push(
              
    ) }else{ content.push(
    ); } }); return (
    {content}
    ); }

提交回复
热议问题