I am trying to add a couple of inputs from multi-select to array. Here is my code. Problem is that in the result previous element in the array is set undefined I have tried to do it in different ways, but it doesn't work.
const SignUp = ({signUp, projectsList}) => {
const [formData, setFormData] = React.useState({
email: '',
password: '',
role: '',
username: '',
projects: [],
});
const handleChange = (name) => (event) => {
console.log("event", event);
if (name === "projects") {
return setFormData({
...formData,
[name]: event.map((v) => v.value),
});
} else {
setFormData({
...formData,
[name]: event.target.value,
});
}
};
const handleSubmit = (event) => {
event.preventDefault();
signUp(formData);
history.push('/');
};
return {
<Select
name="projects"
placeholder="Select Project"
value={formData.projects}
options={projectsList.map((proj) => {
return {
label: proj.name,
value: proj.id
}
})}
key={key + Math.random() + 11 * 1000}
onChange={handleChange('projects')}
isMulti={true}
isClearable={true}
/>
}
The problem:

