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

124
Vistas
React Router ComponentDidMount no se está ejecutando

Necesito que el método componentDidMount se active cuando el enrutador monte un componente para que se pueda iniciar un tiempo de espera. Este tiempo de espera finalmente establece el estado para que no se pueda inicializar en ningún ciclo de vida de procesamiento o en el constructor. Intenté cambiar el component={Home} a render={<Home>} , pero luego aparece el error render is not a function . Realmente no estoy seguro de por qué sucede esto, ¡así que cualquier ayuda sería muy apreciada!

Método de procesamiento de App.js:

 render() { return ( <BrowserRouter> <Navbar /> <Container> <Switch> <Route exact path="/" component={Home} /> <Route exact path="/about" component={About} /> </Switch> </Container> </BrowserRouter> ); }

Inicio.js:

 const Home = (props) => { const images = [ /* Stuff */ ]; return ( <Stack gap={4}> <div> <Card> <Card.Header> <ImageRotator images={images} /> </Card.Header> <Card.Body> <Card.Title>// A Title</Card.Title> <Card.Text> // Text </Card.Text> </Card.Body> </Card> </div> </Stack> ); }

ImageRotator.js:

 class ImageRotator extends Component { constructor(props) { super(props); this.state = { firstImageIndex: 0, renderImages: false, imagesShowing: [], } } componentDidMount() { const imagesShowing = this.calculateImagesToShow(this.state.firstImageIndex); this.setState({ imagesShowing: imagesShowing }); window.addEventListener('resize', () => { const imagesToShow = this.calculateImagesToShow(this.state.firstImageIndex); const imageTimeout = setTimeout(() => this.incrementImageIndex(), 5000); this.setState({ imagesShowing: imagesToShow, imageTimeout: imageTimeout }); }); } calculateImagesToShow(firstImageIndex) { // Returns the images to render on screen } resetImageInterval() { clearTimeout(this.state.imageInterval); this.setState({ imageInterval: setTimeout(() => this.incrementImageIndex(), 5000) }); } incrementImageIndex() { // Increments the state's first image index } decrementImageIndex() { // Decrements the state's first image index } render() { // Renders the calculated images on the screen including two buttons // which when clicked on call the increment and decrement image index functions } }
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