I use react-select and I'm new.I have a component called Example
const colourOptions = [
{ value: '1', label: '1', color: '#00B8D9' },
{ value: '2', label: '2', color: '#0052CC' },
{ value: '3', label: '3', color: '#5243AA' },
];
class Example extends React.Component {
state = {
selectedOption: null,
}
render() {
const { selectedOption, onHandleChange } = this.props;
return (
<Select
onChange={onHandleChange}
options={colourOptions}
/>
);
}
}
export default Example;
In another file we have a functional Component
export default function UserProfile() {
const [selectedOption, setSelectedOption] = useState({});
const handleChange = (selectedOption) => {
setSelectedOption(selectedOption)
console.log(selectedOption)
};
return (
<div>
<Example onHandleChange={handleChange} selectedOption={selectedOption}/>
<Example onHandleChange={handleChange} selectedOption={selectedOption}/>
<Example onHandleChange={handleChange} selectedOption={selectedOption}/>
</div>
);
}
By changing every Example, the value of the previous selectedOption is removed. how to put (merge) all selectedOptions inside one object ?