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

167
Visualizações
react gets stuck after i resize the browser window

I used react-simple-image-slider for image slider on my website, but after i resize the browser window the application gets stucked.

The main Aim is to make the react-simple-image-slider responsive.

The below is the code.

import './App.css';
import {useLayoutEffect, useState } from 'react';
import SimpleImageSlider from 'react-simple-image-slider';

function App() { 
  const [widthAndHeight, setwidthAndHeight] = useState([window.innerWidth, 600]);
  
  useLayoutEffect ( ()=>
  {
    function updateTheWidthAndHeight()
    {
      setwidthAndHeight([window.innerWidth, 600]);
      
    }
      window.addEventListener('resize', ()=>{
      updateTheWidthAndHeight();
    })
  })

  const images = [
    { url: "logos/ethiopia.png" },
    { url: "logos/favicon.ico" },
    { url: "logos/gear.png" },
    { url: "logos/gear.jpg" }
  ];


  return (
      <div>
            <SimpleImageSlider
                style={{ margin: '0 auto', marginTop: '0px'}}
                className="slider"
                width={widthAndHeight[0]}
                height={widthAndHeight[1]}
                slideDuration={1}
                loop={true}
                autoPlay={true}
                images={images}
                showBullets={false}
                showNavs={true}
            />
      </div>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You forgot a dependency list for useLayoutEffect so it's adding an event listener on every render. Add an empty list for one-time execution:

useLayoutEffect(() => {
  function updateTheWidthAndHeight() {
    setwidthAndHeight([window.innerWidth, 600]);
  }
  window.addEventListener("resize", () => {
    updateTheWidthAndHeight();
  });
}, []);
about 4 years ago · Juan Pablo Isaza Relatório

0

I suggest you use useEffect instead of useLayoutEffect.
Maybe it will cause blocking visual updates.

Ref: https://reactjs.org/docs/hooks-reference.html#uselayouteffect

Hope this might help you.

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