Iam working on a little project here, but i had some puzzle to do.
So i had a state of react the value is like this
const [dayValue, setDayValue] = useState({
monday: false,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
saturday: false,
sunday: false,
});
And then i had an array like this
const arrayDays = ['monday', 'wednesday', 'saturday'];
What i want to do is to make all of my key object value that has the same value in arrayDays to change the value become true
I already tried some methods, one of it is i implement it on useEffect like this
for (const x=0; x<arrayDays.length; x++) {
for (const key in dayValue) {
if (key === arrayDays[x]) {
setDayValue({
...dayValue,
[key]: true,
});
break;
}
}
}
but its not working because setState hooks is a async function *CMIIW. does anyone know hot to solve this puzzle ?