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

238
Visualizações
React Keen-Slider detailsChanged function triggers to many re-renders to Slider Item Component

I have a React Slider Component with Keen-Slider.

The Hook looks like this:

const [opacities, setOpacities] = useState([]);

const [sliderRef] = useKeenSlider(
    {
      slides: items.length,
      loop: true,
      detailsChanged(s) {
        const new_opacities = s.track.details.slides.map((slide) =>
          slide.portion
        );
        setOpacities(new_opacities);
      },
    }
)

so whenever the details of the Slider change, i set the opacity and z-index of my Component to the "new_opacities" (new_opacities is like which item is active. The active one gets the number 1 and the not active items 0).

The Component looks like this:

<div ref={sliderRef} className="keen-slider">
    {items.map((item, index) => (
          <div
            key={item.id}
            className="highlight-slide-container"
            style={{ opacity: opacities[index] }}
          >
              ... //content
          </div>
    ))}
</div>

like this it works without bugging. But when i try to export the content to a different Component it gets rlly laggy because i have many re-renders, thats because my state "opacities" change a lot. I tried using React.memo but the new_opacities return [0, 0.1, 0.9] -> [0, 0.2, 0.8] -> [0, 0.3, 0.7] -> ... (so it changes step by step and not immediately to 1 or 0)! So the State always change the value.

This is how i want it to be:

<div ref={sliderRef} className="keen-slider">
        {items.map((item, index) => (
          <HighlightItem item={item} key={item.id} opacity={opacities[index]} />
        ))}
</div>
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