I have basic select component like this.
import { Controller } from "react-hook-form";
import Select, { StylesConfig } from "react-select";
//..
const [universe, setUniverse] = useState<SetStateAction<TOption | unknown>>(null);
<Controller
name="universe_id"
control={control} // this control is imported from react-hook-form nothing special
rules={{ required: true }}
render={({ field }) => (
<Select
{...field}
value={universe}
onChange={handleUniverseChange}
options={universeOptions}
styles={selectStyles as StylesConfig}
/>
)}
/>
And TOption type
export type TOption = {
label: string | number;
value: string | number;
};
Problem is that I can't set correct type for change handler value.
const handleUniverseChange = (item: unknown ) => {
setUniverse(item);
setValue("universe_id", item.value); // object type is unknown
};
Try to use TOption type for item also does not work.
const handleUniverseChange = (item: TOption) => {
Getting error in this line
<Select
{...field}
value={universe}
onChange={handleUniverseChange}
Error: Type "(item: TOption) => void" can't assign for "(newValue: unknown, actionMeta: ActionMeta) => void".