• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

376
Views
Warning: Unexpected ref object provided for input. Use either a ref-setter function or React.createRef(). With React Hook Form

I am new to react-hook-form. I am pasting my code below


import React from "react";
import { useForm } from "react-hook-form";

const Inventory = () => {
  const {
    register,
    handleSubmit,
    formState: { errors },
  } = useForm();
  const onSubmit = (data) => {
    console.log(data);
  };
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input
        className="border border-gray-900 rounded-lg p-2"
        type="number"
        placeholder="Number"
        ref={register("number", { required: true })}
      />
      {errors.number && <p>This is required</p>}
      <button
        className="mt-4 text-white bg-gray-900 border-2 border-gray-900 rounded-md px-2 py-1"
        type="submit"
      >
        Add
      </button>
    </form>
  );
};

export default Inventory;

When I am submitting the form I am not getting any output in the console. Also I am getting an warning as

Warning: Unexpected ref object provided for input. Use either a ref-setter function or React.createRef().

What is the problem here?

Thanks

about 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ok I made a mistake in the code. I wrote this

 ref={register("number", { required: true })}

Instead of this

{...register("number", { required: true })}
about 3 years ago · Juan Pablo Isaza Report

0

For my case i removed ref dotn know whether it is the right fix

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error