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

184
Visualizações
How can I single out which item in my map function should be affected by my function call in react?

I have a series of sliders in a page and I have a specific requirement that requires to add a padding to the slider when there are no items below its 0 index. I have this done already, but I can't figure out how to make this function affect only the slider that I am clicking in. Right now, it affects all the sliders in my map function.

I am using react-elastic-carousel and I am targeting specified props, so the functions look like this

const onPrevStart = (prevItemObject, nextItemObject) => {
  if (nextItemObject?.index === 0) {
    setFirst(true);
  }
};

const onNextStart = (prevItemObject, nextItemObject) => {
  if (nextItemObject?.index !== 0) {
    setFirst(false);
  }
};

then I am calling it in a my map function in the JSX like this

<div className="App">

  {items.map((item, index) => (
    <div 
      key={index} 
      className="carousel-wrapper" 
      style={{ backgroundColor: "maroon" }}>
      <div>
        <Carousel
          breakPoints={breakPoints}
          renderArrow={renderArrows} //see the codesandbox to see these
          onPrevStart={onPrevStart} //here
          onNextStart={onNextStart} //and here
          style={{ backgroundColor: "white" }}>

          {item.itemdata.map((slide, index) => (
            <Item key={index}>{slide}</Item>
          ))}

        </Carousel>
      </div>
    </div>
  ))}
</div>

If you look in my codesandbox that I've made for you to play around with, you can test the functionality and see what I mean.

Thank you in advanced

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