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

172
Views
Obteniendo un error al intentar invocar el método secundario en react.js: TypeError no detectado: no se pueden establecer propiedades de indefinido (estableciendo 'hijo')

Estoy tratando de llamar al método de componente secundario, probé varias soluciones de Internet pero nada funcionó. Aquí está el enlace de stackblitz

Aquí está el fragmento de código

Componente principal

 import React, { Component } from 'react'; import Child from './child'; const Form = (props) => { return ( <div> <Child ref={(instance) => { this.child = instance; }} /> <button onClick={() => { props.callparent(this.child); }} > Click </button> </div> ); }; class Parent extends Component { parentfunc = (childref) => { //invoking child method childref.getAlert(); }; render() { return ( <div> <Form callparent={() => { this.parentfunc(); }} /> </div> ); } } export default Parent;

niño.js

 import React, { Component } from 'react'; class Child extends Component { getAlert() { alert('clicked'); } render() { return <h1>Hello</h1>; } } export default Child;

Cuando intento invocar el método hijo childref.getAlert(); Veo TypeError no detectado: no se pueden establecer propiedades de indefinido (estableciendo 'hijo').

Estoy seguro de que no estoy creando la referencia secundaria correctamente y pasándola a la función para invocar el método secundario. ¿Alguien puede ayudarme aquí?

about 4 years ago · Juan Pablo Isaza
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!