Skip to content

Typescript: register type on custom input #3382

Answered by ritikbanger
joaoreynolds asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @joaoreynolds , 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.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@seedwalk
Comment options

Answer selected by bluebill1049
Comment options

You must be logged in to vote
1 reply
@kajakpalec
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants