Can't set ref to <Input>
See original GitHub issueI am unable to set a ref to a Input
, which I want to use to focus()
on it.
It seems to be because Input
is not declared as a class. (which is required to set refs)
<Input
isColor={emailWarning && 'danger'}
type="email"
placeholder="example@provider.net"
name="email"
value={email}
onChange={this.handleEmailChange}
ref={input => {
this.emailInput = input
}}
/>
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Assigning ref to HTMLInputElement giving error in typescript
In useRef variable cannot set to input element
Read more >Refs and the DOM - React
Refs provide a way to access DOM nodes or React elements created in the render method. In the typical React dataflow, props are...
Read more >Cannot set property with ref callback · Issue #148 - GitHub
I am trying to set a ref attribute using a class method: export default class Foo extends Component { handleClick (event) ...
Read more >FAQs | React Hook Form - Simple React forms validation
Note: Because ref has not been registered, React Hook Form won't be able to register event listeners to the inputs. This means you...
Read more >Focus management with Vue refs - Learn web development
You should see a focus outline on the input for adding new to-do items. ... Inside it, assign your ref to a variable,...
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 FreeTop 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
Top GitHub Comments
Hey @AlgusDark
I’m experiencing the same issue as stated above, so I consider the case still to be ongoing.
Here’s an example setup: https://codesandbox.io/s/black-thunder-8enky?fontsize=14
I did stumbled upon this problem while trying to integrate Bloomer with React Hook Form
The main mechanism to link that lib is using the
register
method as follows:Here’s an integrated example: https://codesandbox.io/s/react-hook-form-get-started-1z7bw?fontsize=14&hidenavigation=1&theme=dark
Any assistance on closing this topic will be appreciated 🙇♂️
Sorry @kachar , the problem is that we don’t have react forward ref in the components.
I decided to rewrite the library to be more friendly. The quickest solution would be to start wrap the components in a forward ref, but my main focus is to rewrite the library as there are some utils that we don’t need and could be done with stronger Types with TS and let the user to deal with errors instead of fix them. But that’s something is not related in this issue.
Would you like to make the
fordwardRef
solution and make a PR?