Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
What type is register from react-hook-form?

When using react-hook-form with Typescript, there is a component that sends some props, register being one of them.

The issue is with its type when declared in an interface:

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

Which is the correct way of declaring register here?

Also tried with:

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

0

You can retrieve register type from UseFormReturn.

import { UseFormReturn } from 'react-hook-form';

export interface MyProps {
  title: string;
  register: UseFormReturn['register'];
}

At react-hook-form, we recommend to forward ref instead of passing register method.

about 4 years ago · Juan Pablo Isaza Relatório

0

if you are calling register as a prop in a custom component or to use in some custom input field in Typescript, then you can use the below code.

First of all import the UseFormRegister and FieldValues from 'react-hook-form'

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

After that, define the type of register as

register: UseFormRegister<FieldValues>

and boom, you don't need to use 'any' type for register.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this.

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda