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

407
Views
Can't put a useRef on the Ant Design drop-down menu button (React Typescript)

I'm using a dropdown list from UI Framework Ant Design, I need to put useRef on it to control it, add or remove Visible={true} attribute. TypeScript gives me this error.

Type '{ children: Element; ref: MutableRefObject; className: string; overlay: Element; trigger: "click"[]; }' cannot be assigned to type 'IntrinsicAttributes & DropDownProps & { children? ReactNode; }'. The 'ref' property does not exist for the type 'IntrinsicAttributes & DropDownProps & { children? ReactNode; }'.

Below are two screenshots, Dropdown Button element and TS error

enter image description here

enter image description here

UPDATE**

My temporary solution looks like this, if I'm on the home page my drop down list is open, if I'm on other pages it opens after a click. But it would be better if through Ref, you could set or remove the attribute visible={true} enter image description here

source code link https://github.com/grigoryanhrant/my-app/blob/master/src/components/Header/index.tsx

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

0

React components do not have a ref prop by default, only base elements like <div> and <span> etc. do. In order for a React component to pass through a ref prop, you must use React.forwardRef().

It looks like the antd "Dropdown" component does not utilize React.forwardRef(), so you are screwed in this case. Of course, you could check their contribution guidelines and explore submitting an update to their codebase to implement this...

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!