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

168
Vistas
How to access props from a component that extends another component in React?

I have 3 components:

-Component A
    -Component B
        -Component C extends Component B

I'm passing a function as props from Component A to Component B and want to call the function in Component C.

I've tried added:

constructor(props) {
   super(props);
   this.props.validationsFunc = this.props.validationsFunc.bind(this);
}

and variations with/without props on either side of the bind in Component B. But when I try calling this.props.validationsFunc() in Component C, I get the error saying it is not a function.

class ComponentA extends PureComponent {
    const validationsFunc = () => {
        console.log('hi');
    };
    <ComponentB validationsFunc={validationsFunc} />
}


class ComponentB extends PureComponent {
   static propTypes = {
      validationsFunc: PropTypes.func
   };

   constructor(props){
      super(props);
      this.props.validationsFunc = this.props.validationsFunc.bind(this)
   }
}

   
class ComponentC extends ComponentB {
    this.props.validationsFunc();
}

How do I access this function in Component C without directly passing props to it?

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