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

238
Views
Reaccionar convertir ganchos a clase pero obtener error

Quiero convertir el componente de ganchos de reacción en un componente de clase, pero aparece un error.

MANOS

 import React, { useEffect, useRef } from "react"; const App = () => { const refValt = useRef(null); const myfuncValt = () => { console.log("222222222222222222222"); }; useEffect(() => { setTimeout(() => { refValt.current.click(); }, 5000); //miliseconds }, []); return ( <div> <div ref={refValt} onClick={myfuncValt}>Valt</div> </div> ); }; export default App;

CLASE

 import React from "react"; const myfuncValt = () => { console.log("222222222222222222222"); }; class App extends React.Component { constructor(props) { super(props); const refValt = React.createRef(null); } componentDidMount() { setTimeout(() => { this.refValt.current.click(); }, 5000); } render() { return ( <div> <div ref={this.refValt} onClick={myfuncValt}> Valt </div> </div> ); } } export default App;

me sale este error =

ingrese la descripción de la imagen aquí

Intento this.refValt.click(); Pero no funciona.

En realidad, sospecho las diferencias entre createref y userref.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Este:

 const refValt = React.createRef(null);

... tiene que ser esto:

 this.refValt = React.createRef(null);
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!