A
A
Alexander2021-08-17 13:12:44
typescript
Alexander, 2021-08-17 13:12:44

How to add typing for reusable React components?

Hello, can you please tell me how to add typing for reusable React components?
I have a select component that should be typed relative to the form where it is used, how can I implement this, I need to have a dynamic interface instead of IRegisterInputs, because now this value is hardcoded

export type IRegisterInputs = {
  email: string
  password: string
  firstName: string
  lastName: string
  dateOfBirth: string
  country: string
  gender: string
  subscribe: boolean
};

interface SelectProps {
  control: Control<IRegisterInputs>
  name: keyof IRegisterInputs
  options: CountriesOptions[]
  setValue: UseFormSetValue<IRegisterInputs>
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question