Skip to content

Instantly share code, notes, and snippets.

View amarjanica's full-sized avatar

Ana Bujan amarjanica

View GitHub Profile
@amarjanica
amarjanica / ControlledAutocomplete.tsx
Created June 18, 2024 10:04
Mui Autocomplete/React Hook Form generic controlled component
import { Control, Controller, FieldPath, FieldValues } from 'react-hook-form';
import Autocomplete, { AutocompleteRenderInputParams } from '@mui/material/Autocomplete';
import React from 'react';
type Props<OptionType, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = {
control: Control<TFieldValues>,
getOptionKey: (value: OptionType) => string,
getOptionLabel: (value: OptionType) => string,
name: TName,
options: OptionType[],