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

203
Visualizações
React parent component props can't access using forwardRef props in child component

I have Child Component Like this.

Parent => Child

When I send props to my child component from the parent component. The prop can't access child components.

const Parent = () => {
    const [renderCount, setRenderCount] = useState(4);

    const renderCountHandler = () => {
        setRenderCount(renderCount + 1);
    };

    return (
        <div>
           <Child renderCountHandler={renderCountHandler}/>
        </div>
    );
};


const Child = forwardRef((props, ref) => {

    //Can't access props.renderCountHandler Only props.children
    <div>{props.}</div>
});

I am a new student for reactjs. So I don't know much about it. If anyone can help me with this. It's a realy help for me to my studies.❤️

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can pass state or method as props parent to child component.

Read more here components-and-props

Example:

const { forwardRef, useState } = React;

const Parent = () => {
  const [renderCount, setRenderCount] = useState(4);

  const renderCountHandler = () => {
    setRenderCount(renderCount + 1);
  };

  return (
    <div>
      <p>{renderCount}</p>
      <br />
      <Child renderCountHandler={renderCountHandler} />
    </div>
  );
};

const Child = forwardRef((props, ref) => {
  //Can't access props.renderCountHandler Only props.children
  return (
    <div ref={ref}>
      <button onClick={props.renderCountHandler}>Click Me</button>
    </div>
  );
});

ReactDOM.render(<Parent />, document.getElementById("root"));
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<div id="root"></div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Everything is ok in your code. I get the "renderCountHandler" props. See the sandbox

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