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

197
Views
Los accesorios del componente principal de React no pueden acceder usando los accesorios forwardRef en el componente secundario

Tengo un componente secundario como este.

Padre => Hijo

Cuando envío accesorios a mi componente secundario desde el componente principal. El accesorio no puede acceder a los componentes secundarios.

 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> });

Soy un nuevo estudiante de reactjs. Así que no sé mucho al respecto. Si alguien me puede ayudar con esto. Es una gran ayuda para mí en mis estudios.❤️

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

0

Puede pasar state o el method como props padre a hijo.

Lea más aquí componentes y accesorios

Ejemplo:

 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 Report

0

Todo está bien en tu código. Obtengo los accesorios "renderCountHandler". Ver la caja de arena

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!