I have a form
<Form onSubmit={handleSubmit(applyFilter)}>
<FormLabel>Organization</FormLabel>
<Controller
name="Units"
control={control}
render={({ field }) =>
<Select
{...field}
placeholder={translate("Select organization")}
options={filterModel.data?.units.map(unit =>
{ return { label: unit.name, value: unit.id } })}
isMulti
closeMenuOnSelect={false}
/>
}/>
</Form>
But i have an error when i try to set options – type "{ label: string; value: number; }[] | not specified" cannot be specified for the type "OptionsOrGroups<string, GroupBase<string>> | undefined".
can you help me with this type?
2
Answers
You need the imports like this,
Then your hook component can be like this,
This looks like a very general question, but to use react-select with react-hook-form in TypeScript, you need to follow these steps.
Make sure you have the following packages installed in your project:
Set up the form and form validation
Define the form schema using yup for validation:
Initialize the form and apply the form resolver:
Add the react-select component
Add the Select component to your form: