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

208
Views
¿Qué tipo es el registro de la forma de gancho de reacción?

Cuando se usa la forma de gancho de reacción con Typescript, hay un componente que envía algunos accesorios, siendo el register uno de ellos.

El problema es con su tipo cuando se declara en una interfaz:

 export interface MyProps { title: string; ... register: (string | undefined) => void; }

¿Cuál es la forma correcta de declarar register aquí?

También probé con:

 import { RegisterOptions } from 'react-hook-form'; export interface MyProps { title: string; ... register: RegisterOptions; }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede recuperar el tipo de registro de UseFormReturn .

 import { UseFormReturn } from 'react-hook-form'; export interface MyProps { title: string; register: UseFormReturn['register']; }

En react-hook-form, recomendamos reenviar ref en lugar de pasar el método de register .

about 4 years ago · Juan Pablo Isaza Report

0

si está llamando a registrarse como accesorio en un componente personalizado o para usar en algún campo de entrada personalizado en Typescript, entonces puede usar el siguiente código.

En primer lugar, importe UseFormRegister y FieldValues desde 'react-hook-form'

 import {UseFormRegister, FieldValues } from 'react-hook-form'

Después de eso, defina el tipo de registro como

 register: UseFormRegister<FieldValues>

y boom, no necesita usar 'cualquier' tipo para registrarse.

about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto.

 import { RegisterOptions, UseFormRegisterReturn } from 'react-hook-form'; export interface MyProps { title: string; ... register: (name: string, options?: RegisterOptions) => UseFormRegisterReturn; }
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!