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

174
Views
Obtenga el valor <p> usando React ref

¿Hay alguna forma de obtener este valor de "nombre" después de hacer clic en el elemento li y establecerlo en el estado de rama seleccionada usando ref?

 const [selectedBranch, setSelectedBranch] = useState(null); const selectRef = useRef(); const selectDeliveryBranch = () => {}; return ( <li onClick={selectDeliveryBranch} > <p ref={selectRef}>{props.name}</p> </li>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No desea utilizar ref para hacer esto, simplemente cree una devolución de llamada:

 return <li onClick={()=>setSelectedBranch(props.name)}> <p>props.name</p> </li>

No necesita ref.

about 4 years ago · Juan Pablo Isaza Report

0

¿Estás seguro de que necesitas usar la referencia? ¿Por qué no puedes hacer eso?

 const [selectedBranch, setSelectedBranch] = useState(null); const selectRef = useRef(); return ( <li onClick={() => setSelectedBranch(props.name)} > <p ref={selectRef}>{props.name}</p> </li>
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!