I’m using react-select but I have a data in object not in array & in options only accepting array values. How can I solve it?
<Select
options={ccUsers}
onChange={handleChange}
/>
Working data :-
const ccUsers = [
{ value: 'One', label: 'One' },
{ value: 'Two', label: 'Two' },
];
But getting data in this format :-
const ccUsers = {
"test": "testing",
"test": "testing"
}
>Solution :
You can use Object.entries to convert into Array
const obj = {
'One': 'One',
'Two': 'Two',
};
const ccUsers = Object.entries(obj).map(([key, value]) => ({
label: key,
value
}))
console.log('>>>>> ccUsers : ', ccUsers);