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

137
Visualizações
Previous article can't be same as next one

I currently have code that gets all articles from a CMS, with a number, image and text and based on a true or false, the order of image text gets decided. So a image can be above text or under text. But I want it so it's always: image under - image above - image under - image above, and not that it can be like image under - image under - image top, so it can't be allowed to have imaged under for two articles next to each other.

Does someone have an idea what I can do to accomplish this? My current code:

export const GridArticle = ({ item, idx }) => {
  const img = item.image;

  // If true, image at the top, if false, image at the bottom
  const dataOrder = [true, false];
  dataOrder.sort(() => Math.random() - 0.5);
  console.log(dataOrder[0]);

  return (
    <Wrapper>
      {dataOrder[0] ? (
        <Wrapper>
          <a href={`/articles/${item._meta?.uid}`}>
            <Number>{idx + 1}</Number>
            <ImageWrapper>
              {img && <img src={img.url} alt={img.alt} style={{ marginBottom: '2rem' }} />}
            </ImageWrapper>
            <div>
              <h2>{item.title[0].text}</h2>
              <RichText render={item.intro} />
              <span className="link">Lees verder</span>
            </div>
          </a>
        </Wrapper>
      ) : (
        <Wrapper>
          <a href={`/articles/${item._meta?.uid}`}>
            <Number>{idx + 1}</Number>
            <div>
              <h2>{item.title[0].text}</h2>
              <RichText render={item.intro} />
              <span className="link">Lees verder</span>
            </div>
            <ImageWrapper>
              {img && <img src={img.url} alt={img.alt} style={{ marginTop: '2rem' }} />}
            </ImageWrapper>
          </a>
        </Wrapper>
      )}
    </Wrapper>
  );
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

if I understand correctly, you want your pictures to be through one bottom top of them top you can look at the index and if the element is even make a picture at the bottom odd at the top number % 2 === 0 ? "true" : "false"

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