I have the following react-select code which all works fine and sets my Formik state values.
const [selectedOptions, setSelectedOptions] = useState([]);
<Select
options={myOptions}
isMulti={true}
name={`myGroups.${index}.selectedOptions`}
onChange={(selectedOptions) => {
let e = { target: { name: `myGroups.${index}.selectedOptions`, value: selectedOptions } };
handleChange(e);
handleChangeIndex(index);
}}
/>
My question is, during the onChange I also want to call another function: handleChangeIndex to set state values, i.e.:
const handleChangeIndex = index => selectedOption => {
console.log("inside handleChangeIndex....")
const optionsCopy = [...selectedOptions];
optionsCopy[index] = selectedOption;
setSelectedOptions(optionsCopy);
};
In my <Select> above, my function handleChangeIndex(index) is not being called as I am not seeing a console.log message but if I call the <Select> as follows with just my handleChangeIndex alone it works.
<Select
options={myOptions}
isMulti={true}
name={`myGroups.${index}.selectedOptions`}
onChange={handleChangeIndex(index)}
/>
Can people pls assist with how to call my function as in the top <Select>