Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Trying to make a slideshow, not behaving as expected

I'm trying to make a slideshow that rotates between images every 5 seconds, or if a button is pressed. If a button is pressed, the slideshow should stop for about 30 seconds (to allow the user to stop and read each slide)

Sorry for noob questions, I'm pretty new to coding

If anyone can help here is my code,

import './App.css';
import pic1 from './images/red.jpg'
import pic2 from './images/green.jpg'
import pic3 from './images/pink.jpg'
import pic4 from './images/blue.jpg'
import * as FaIcons  from "react-icons/fa";
import * as IoIcons  from "react-icons/io5";

var i = 0;
var images = [];
var time = 3000;

images[0] = pic1
images [1] = pic2
images[2] = pic3
images [3] = pic4

function App() {

const [buttonPressedRecently, setPressedRecently]  = React.useState(false);

function changeImage() {
    if (i < images.length - 1){
        i++;
    } else {
        i = 0;
    }
document.getElementById('sponsorImage').src = images [i];
}

function clickedButton() {
  setPressedRecently(true)
  setTimeout(() => {
    setPressedRecently(false)
    console.log(buttonPressedRecently);
  }, 30000);
    changeImage();
  console.log('====================================');
  console.log(buttonPressedRecently);
  console.log('====================================');
}

if (buttonPressedRecently) {
  }
if (!buttonPressedRecently) {
  setInterval(() => {
    changeImage();
  }, 5000);
  }

  return (
    <>

    <div className='Blackbox'>
    <p className='sponsoredText'>Sponsored tokens...</p>
   <button className='nextbtn' onClick={clickedButton}><FaIcons.FaAngleLeft className='arrowicons'/></button>
   <button className='prevbtn' onClick={clickedButton}><FaIcons.FaAngleRight className='arrowicons'/></button>
   <button className='qrbtn'> <IoIcons.IoQrCodeOutline className='arrowicons'/></button>
    <div className='centerline'>

    <img id="sponsorImage" />
   </div>
    </div>
    </>
  );
}

export default App;

I would be delighted if anybody can help. I'm very new to coding

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda