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

192
Visualizações
Select a grid element from a .map

I have a grid and I need to select the fourth element and move from the first column to second column in the row below. I know how to do it in plain html, but not how to select the grid element inside a map.

Here the code:

  return (
    <Layout pageTitle='Projects'>
      <GridIndex>
        {data.allMdx.nodes.map((node) => (
          <article key={node.id} className=''>
            <Link to={`/projects/${node.slug}`}>
              <div>{node.frontmatter.title}</div>
              <GatsbyImage
                image={getImage(node.frontmatter.imageCover)}
                alt={node.frontmatter.imageCoverAlt}
                className='h-auto xs:square'
              />
            </Link>
          </article>
        ))}
      </GridIndex>
    </Layout>
  );
};

I just need to select the fourth element and put this className: className='col-start-2'

Here an image to understand the problem: grid

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use the index of the map to check if its the 4th iteration.

return (
  <Layout pageTitle='Projects'>
    <GridIndex>
      {data.allMdx.nodes.map((node, i) => (
        <article key={node.id} className={i === 3 ? 'col-start-2' : ''}>
        ...
about 4 years ago · Juan Pablo Isaza Relatório

0

first of all, you should save the data.allMdx.nodes in a state, I'm sure you already know that

then whenever you want to swap some element with another one you can do this:

const swap=()=>{
const tmp=[...listState]
    // here you do the changes to the tmp list
setState(tmp)
}

return (
    <Layout pageTitle='Projects'>
      <GridIndex>
        {state.map((node) => (
          <article key={node.id} className=''>
            <Link to={`/projects/${node.slug}`}>
              <div>{node.frontmatter.title}</div>
              <GatsbyImage
                image={getImage(node.frontmatter.imageCover)}
                alt={node.frontmatter.imageCoverAlt}
                className='h-auto xs:square'
              />
            </Link>
          </article>
        ))}
      </GridIndex>
    </Layout>
 );
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