Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda