I am new to react, my problem is, I have one dropdown in which there are two options A and B, Example: As shown below this is my dropdown display options dynamically in my case options are A and B.
<DropDown
selectedData={Options}
/>
Custom DropDown:
const onChange = (value) => {
!isMulti && setToggle(!toggle);
onChecked(value);
}
const createOptions = () => {
if (data && data.length > 0) {
return data.map(({ value}, index) => {
if (isMulti) {
return (
<div key={index}>
<input type="checkbox"
onChange={() => onChange(value)}
checked={selectedOrNot(value)}
/>
</div>
)
} else {
return (
<div key={index}
onClick={() => onSelectionChange(value)}
</div>
);
}
});
}
else {
return <div>No data found</div>
}
}
Also, I have JSON data which consists of two objects in it. for eg:
data: {
A: {
num1: "0.241",
num2: "15.293",
},
B: {
num1: "0.241",
num2: "15.293",
},
}
So what I want is whenever users select A as an option from dropdown it will render A object eg: data.A. Similarly when users select B as an option it will render B object eg: data.B. Please help.
data
an object? because you can only.map()
an array of objectsconst data = [{num1: "...", num2: "..."}, {num1: "...", num2: "..."}]