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

165
Views
Get <p> value using React ref

Is there some way to get this "name" value after clicking on li item and set it to selectedBranch state using 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

You do not want to use ref to do this, instead simply create a callback:

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

No ref needed

about 4 years ago · Juan Pablo Isaza Report

0

are you sure you need to use the ref ? Why can't you do that ?

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!