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

145
Visualizações
Change Component Alignment for each time map function runs React JS

I am making a person website and in the Home page I have a shortened version of my portfolio. What I'm trying to accomplish is to switch the alignment of the image and text each time a component is rendered by the .map() function

This is my code so far

import Image from 'next/image';
import React, { useState } from 'react';
import portoflio from '../../Works/data';

export default function MainWork() {
  const works = portoflio.slice(0, 3);
  const [align, setAlign] = useState(false);
  return (
    <div className="text-center">
      {works.map((work) => {
        setAlign(!align) //The Problem Producing Line
        const { name, text, imageLink, keys } = work;
        return (
          <div className="justify-center flex" key={name}>
            <div className={'w-60 h-60 ' + (align ? null : 'order-2')}>
              <Image
                className={'rounded-xl overflow-hidden w-full h-full'}
                src={'/work/' + imageLink + '.svg'}
                alt={'Image of ' + imageLink}
                width="100%"
                height="100%"
                layout="responsive"
              />
            </div>
            <h1>{name}</h1>
          </div>
        );
      })}
    </div>
  );
}

The ternary operator in Image container should take care of the alignment but the issue I'm facing is that if I try to switch the state every time the loop runs I get this error: Picture of Error Produced I tried to find an image for reference and this is the closest i could find: Picture for reference

about 4 years ago · Juan Pablo Isaza
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