I have the following code sequence where some calendar data is checked with scheduling data. The problem is that if there are 2 or more appointments, I get the rest duplicated, tripled. How can I change?
{ programari.map(val=>{
if(val.date==selectedDate){
if(val.hour==hour){
return(
<RadioButton.Item label={hour} value={hour} disabled={true} style={{backgroundColor:'red',opacity:0.4}} />
)
}
else return <RadioButton.Item label={hour} value={hour} disabled={false} style={{backgroundColor:'green',opacity:0.4}} />
}
})}
Did you check the contents of programari? is you have duplicates in this list you will need to erase the duplicates. It is easy to avoid duplicates if somehow you use a set and from the set you create programari. On the other hand, shouldn't you consider minutes, too? Dominic also suggested the use of a Key and this is true. As key, you can use the index of the element in programari concatenated with something else to get a unique value.