ref not working in React-Bootstrap + TypeScript
See original GitHub issueDescribe the bug
If I use ref with register in a Control
the value is invalid.
No overload matches this call.
Overload 1 of 2, '(props: Readonly<ReplaceProps<"input", BsPrefixProps<"input"> & FormControlProps>>): FormControl<"input">', gave the following error.
Type '(ref: ElementLike) => void' is not assignable to type '(string & ((instance: HTMLInputElement) => void)) | (string & RefObject<HTMLInputElement>) | (((instance: FormControl<"input">) => void) & ((instance: HTMLInputElement) => void)) | (((instance: FormControl<...>) => void) & RefObject<...>) | (RefObject<...> & ((instance: HTMLInputElement) => void)) | (RefObject<...> ...'.
Type '(ref: ElementLike) => void' is not assignable to type 'string & ((instance: HTMLInputElement) => void)'.
Type '(ref: ElementLike) => void' is not assignable to type 'string'.
Overload 2 of 2, '(props: ReplaceProps<"input", BsPrefixProps<"input"> & FormControlProps>, context?: any): FormControl<"input">', gave the following error.
Type '(ref: ElementLike) => void' is not assignable to type '(string & ((instance: HTMLInputElement) => void)) | (string & RefObject<HTMLInputElement>) | (((instance: FormControl<"input">) => void) & ((instance: HTMLInputElement) => void)) | (((instance: FormControl<...>) => void) & RefObject<...>) | (RefObject<...> & ((instance: HTMLInputElement) => void)) | (RefObject<...> ...'.
Type '(ref: ElementLike) => void' is not assignable to type 'string & ((instance: HTMLInputElement) => void)'.
Type '(ref: ElementLike) => void' is not assignable to type 'string'.ts(2769)
index.d.ts(104, 9): The expected type comes from property 'ref' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FormControl<"input">> & Readonly<ReplaceProps<"input", BsPrefixProps<"input"> & FormControlProps>> & Readonly<{ children?: ReactNode; }>'
index.d.ts(104, 9): The expected type comes from property 'ref' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FormControl<"input">> & Readonly<ReplaceProps<"input", BsPrefixProps<"input"> & FormControlProps>> & Readonly<{ children?: ReactNode; }>'
if instead of register()
I use () => register()
the code compiles but is not registering the input.
Screenshots
Issue Analytics
- State:
- Created 4 years ago
- Comments:21 (9 by maintainers)
Top Results From Across the Web
react-bootstrap-typeahead TypeScript- Ref - getInstance does ...
The variable typeahead which you created from createRef is a RefObject with a property current that references your component.
Read more >Tab components - React-Bootstrap
Dynamic tabbed interfaces should not contain dropdown menus, as this causes both usability and accessibility issues. From a usability perspective, ...
Read more >Introduction - React-Bootstrap
Learn how to include React Bootstrap in your project. Installation#. The best way to consume React-Bootstrap is via the npm package which you...
Read more >Overlays | React-Bootstrap
The <Tooltip> and <Popover> components do not position themselves. Instead the <Overlay> (or <OverlayTrigger> ) components, inject ref and style props.
Read more >List Group - React-Bootstrap
Set the active prop to indicate the list groups current active selection. Cras justo odio; Dapibus ac facilisis in; Morbi leo risus; Porta...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
From what I’ve tried, it seems that it’s only a mismatch between how RHF and React-Bootstrap type a
ref
. It works perfectly by doing a simple cast:Thank you @bluebill1049 for putting time into this, right now I am finishing a product and have no time to supply the codesandbox example this week. by the way, I used the <Controller> component and it worked very well without adding to much verbosity.
I will try to come back to this next week and provide the codesandbox.
Thank you for this great lib.