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

966
Views
TypeError: no se pueden leer las propiedades de null (leyendo 'useRef')

Estoy usando Next.js, TypeScript, cordura y tailwindcss. Estoy tratando de usar el formulario de gancho de reacción pero recibo un error.

He intentado:

  • cambiando la función Post a una función de flecha
  • cambiar la función Post a una función const
  • cambiar la interfaz IFormInput a un tipo

Aquí es donde está el error:

 23 | formState: { errors }, > 24 | } = useForm<IFormInput>(); | ^ 25 | 26 | return ( 27 | <main>

Y este es mi código ([slug].tsx) en la carpeta de páginas :

 import { useForm, SubmitHandler } from "react-hook-form"; interface IFormInput { _id: string; name: string; email: string; comment: string; } function Post({ post }: Props) { const { register, handleSubmit, formState: { errors } } = useForm<IFormInput>(); return ( <form> <input {...register("_id")} type="hidden" name="_id" value={post._id} /> <input {...register("name", { required: true })} type="text"/> <input {...register("email", { required: true })} type="text" /> <textarea {...register("comment", { required: true })} /> {errors.name && (<span>- The Name Field is required</span>)} {errors.comment && ( <span>- The Comment Field is required</span>)} {errors.email && ( <span>- The Email Field is required</span>)} <input type="submit" /> </form> ); }

Cualquier ayuda es muy apreciada. ¡Gracias!

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

0

Decir que no puede leer useRef significa que no está encontrando React. Este problema puede ocurrir si no tiene la versión estable de Node.js, actualmente v16.15.1 , como puede ver en el documento oficial. Si es el caso, asegúrese de degradarlo, y para eso puede usar n paquete de npm :

 npm i -gn n stable # if one of the commands does not pass, you may need to use sudo sudo npm i -gn sudo n stable

Elimine node_modues , package-lock.json y yarn.lock si está usando yarn . Luego inicie su servidor de desarrollo:

 rm -rf node_modules package-lock.json yarn.lock npm install npm run dev
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!