I have a state,
const [weekdays, setWeekdays] = useState([{
day: 'S',
fullName: 'Sunday',
select: false
},
{
day: 'M',
fullName: 'Monday',
select: false
},
{
day: 'T',
fullName: 'Tuesday',
select: false
},
{
day: 'W',
fullName: 'Wednesday',
select: false
},
{
day: 'T',
fullName: 'Thursday',
select: false
},
{
day: 'F',
fullName: 'Friday',
select: false
},
{
day: 'S',
fullName: 'Saturday',
select: false
}])
I have newData,
const newData=['Monday', 'Wednesday', 'Thursday']
I want to update that weekDays state to select: true for those days which are present in newData and others remains same.
I am trying in this way,I know this is not the correct way to update state,
useEffect(() => {
{
if (data?.length > 0) {
setWeekdays(weekdays=>([...weekdays,data]))
}
}
}, [data]);
If any one knows the answer then suggest me,How to achive this?
Thanks in advance...