I am using react hook form and react select with typescript . Its works fine for single selected value. But when I choose isMulti for multiple selected value , I am unable to get the value from the submitted form . Here is the code
interface ITopic {
value: string;
label: string;
}
...........
const topicOptions : ITopic[] = [
{ value: 'javascript', label: 'JAVASCRIPT' },
{ value: 'php', label: 'PHP' },
{ value: 'python', label: 'PYTHON' },
{ value: 'java', label:'JAVA' },
{ value: 'C#', label: 'C#' }
]
type TopicType = { label: string, value: string }
const [selectedTopic, setSelectedTopic] = useState<readonly ITopic[]>([]);
..........
<Controller
control={control}
render={({ field: { onChange, value, name, ref } }) =>{
const handleSelectionChange = (topicOptions: readonly SelectOptionType[]) => {
setSelectedTopic(topicOptions)
console.log(selectedTopic)
}
return (
<Select
isMulti
name={name}
value={selectedTopic}
options={topicOptions}
onChange={handleSelectionChange}
/>
)}}
name="topics"
/>
I am getting empty topics value. Need Help. Thank you.