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:
JavaScript
x
20
20
1
return (
2
<Layout pageTitle='Projects'>
3
<GridIndex>
4
{data.allMdx.nodes.map((node) => (
5
<article key={node.id} className=''>
6
<Link to={`/projects/${node.slug}`}>
7
<div>{node.frontmatter.title}</div>
8
<GatsbyImage
9
image={getImage(node.frontmatter.imageCover)}
10
alt={node.frontmatter.imageCoverAlt}
11
className='h-auto xs:square'
12
/>
13
</Link>
14
</article>
15
))}
16
</GridIndex>
17
</Layout>
18
);
19
};
20
I just need to select the fourth element and put this className:
className='col-start-2'
Here an image to understand the problem: grid
Advertisement
Answer
You can use the index
of the map to check if its the 4th iteration.
JavaScript
1
7
1
return (
2
<Layout pageTitle='Projects'>
3
<GridIndex>
4
{data.allMdx.nodes.map((node, i) => (
5
<article key={node.id} className={i === 3 ? 'col-start-2' : ''}>
6
7