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

201
Views
Custom input component with React Hook Form 7

So I have this component:

const TextInput = ({ type = 'text', fullWidth = false, ...rest }) => {
  return (
    <input
      type={type}
      className={`text-input ${classNames([fullWidth, 'fullwidth'])}`}
      {...rest}
    />
  );
};

and then I have this code:

const { register } = useForm();

//then in the return
<TextInput type='email' fullWidth {...register('email')} />

And I'm getting this error:

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

How can I solved this? From what I looked I have to pass refs to the input but I don't know how to do this..

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

0

Okay so what I needed to do is use forwardRef like this:

const TextInput = React.forwardRef(({ type = 'text', fullWidth = false, ...rest }, ref) => {
  return (
    <input
      type={type}
      className={`text-input ${classNames([fullWidth, 'fullwidth'])}`}
      {...rest}
    />
  );
});
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!