Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
Repeat two at a time with a map

For example, id... I want -> "ID" in one line 1, 2, next line 3, 4 next line 5, 6 now -> one line 1, 1 next line 2, 2 next line 3, 3. What should I do? For example, id... I want -> "ID" in one line 1, 2, next line 3, 4 next line 5, 6 now -> one line 1, 1 next line 2, 2 next line 3, 3. What should I do?

//app.js
  const [data, setData] = useState([]);

  useEffect(() => {
    fetch('http://localhost:3001/data/mainData.json')
      .then(res => res.json())
      .then(data => {
        setData(data);
      });
  }, []);

        <ImgContainer>
          {data.map(imgList => {
            
            return (
              <ImgBox>
                <ImgWrap to={`/${imgList.text}`} key={imgList.id}>
                  <Img src={imgList.src} alt={imgList.text} />
                  <Text>{imgList.text}</Text>
                </ImgWrap>
                <ImgWrap to={`/${imgList.text}`} key={imgList.id}>
                  <Img src={imgList.src} alt={imgList.text} />
                  <Text>{imgList.text}</Text>
                </ImgWrap>
              </ImgBox>
            );
          })}
        </ImgContainer>
//json
[
  {
    "id": 1,
    "src": "/images/bathMain.jpg",
    "text": "Bath"
  },
  {
    "id": 2,
    "src": "/images/livingMain.jpg",
    "text": "Living"
  },

  {
    "id": 3,
    "src": "/images/kitchenMain.jpg",
    "text": "Kitchen"
  },

  {
    "id": 4,
    "src": "/images/diningMain.jpg",
    "text": "Dining"
  },

  {
    "id": 5,
    "src": "/images/bedMain.jpg",
    "text": "Bed Room"
  },
  {
    "id": 6,
    "src": "/images/dressMain.jpg",
    "text": "Dress Room"
  }
]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One way to do this would be to create your expression outside the returns statement, using a simple for loop :

  let val = [
    {
      id: 1,
      src: "/images/bathMain.jpg",
      text: "Bath"
    },
    {
      id: 2,
      src: "/images/livingMain.jpg",
      text: "Living"
    },

    {
      id: 3,
      src: "/images/kitchenMain.jpg",
      text: "Kitchen"
    },

    {
      id: 4,
      src: "/images/diningMain.jpg",
      text: "Dining"
    },

    {
      id: 5,
      src: "/images/bedMain.jpg",
      text: "Bed Room"
    },
    {
      id: 6,
      src: "/images/dressMain.jpg",
      text: "Dress Room"
    }
  ];

  let expr = [];
  for (let i = 0; i < val.length; i=i+2) {
    expr.push(
      <>
        <p>{val[i].id}</p>
        <p>{val[i+1].id}</p>
      </>
    );
  }

  return <div className="App">{expr}</div>;


Link

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda