Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
reaccionar se atasca después de cambiar el tamaño de la ventana del navegador

Usé react-simple-image-slider para el control deslizante de imágenes en mi sitio web, pero después de cambiar el tamaño de la ventana del navegador, la aplicación se atasca.

El objetivo principal es hacer que el control deslizante de imagen simple de reacción responda.

El siguiente es el código.

 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 answers
Answer question

0

Olvidó una lista de dependencias para useLayoutEffect , por lo que está agregando un detector de eventos en cada procesamiento. Agregue una lista vacía para una ejecución única:

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

0

Le sugiero que use useEffect en lugar de useLayoutEffect .
Tal vez cause el bloqueo de actualizaciones visuales.

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

Espero que esto pueda ayudarte.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!