question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[HELP] Input DomRef Register Property 'current' is missing

See original GitHub issue

Hello, I am using React Bulma Components and React Form Hooks packages. At the input:

type FormValues = {
    email: string;
    password: string
}
const {
    register, 
    handleSubmit, 
    formState: 
    { 
        errors, 
        isSubmitSuccessful, 
        isSubmitting 
    } 
} = useForm<FormValues>();

#return

<Form.Input
    name="email"
    domRef={register({required: true})}
    type="email"
    placeholder="e.g. bobsmith@gmail.com"
    required
/>

Gives me this error:

Property ‘current’ is missing in type ‘UseFormRegisterReturn’ but required in type ‘RefObject<“input”>’.

Its inside a functional component. I think I am doing something completely wrong and misunderstanding something,

I found same issue here but I couldn’t understand how to fix this.

I tried this fix: #343 (comments)

But then I get this error because I use functional component?

328 at react-hook-form

Thanks a lot.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Asim-Acommented, Jan 6, 2022
export const InputWithRef = React.forwardRef<"input", any>((props, ref) => {
    return <Form.Input {...props} domRef={ref} />;
});

That piece of code works in TS. It is not so elegant as it only works for Form.Input, but works

I can confirm that this works, thank you @sebzieja 🤝

2reactions
sebziejacommented, Aug 27, 2021
export const InputWithRef = React.forwardRef<"input", any>((props, ref) => {
    return <Form.Input {...props} domRef={ref} />;
});

That piece of code works in TS. It is not so elegant as it only works for Form.Input, but works

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use refs in React with Typescript - Stack Overflow
When the component mounts, the ref attribute's current property will be assigned to the referenced component/DOM element and assigned back to ...
Read more >
Refs and the DOM - React
createRef() receives the underlying DOM element as its current property. When the ref attribute is used on a custom class component, the ref...
Read more >
React Refs with TypeScript - Medium
React will assign the current property with the DOM element when the component mounts, and assign it back to null when it unmounts....
Read more >
Understanding refs in Vue - LogRocket Blog
Refs are Vue.js instance properties used to register a reference ... Vue's ref helps you “reference” DOM elements in a more efficient way....
Read more >
Template Refs - Vue.js
To achieve this, we can use the special ref attribute: template <input ref="input">. ref is a special attribute, similar to the key attribute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found