How console log variables inside find method that inside a map method and return an object ? That is an arrow function so I should use with function body and return statement. But I get error if i do.
So how can console log lbl and lbl.label inside find method?
Yes i should read how use arrow function. (this is exactly what I want to find out, among other things) Thank you
useEffect(() => {
setLabels((prevLabels) => {
return [...new Set(savedEvents.map((evt) => evt.label))].map((label) => {
const currentLabel = prevLabels.find((lbl) => lbl.label === label);
console.log(`prevlabels: ${JSON.stringify(prevLabels)}`);
console.log(`currentLabel: ${JSON.stringify(currentLabel)}`);
console.log(`currentLabel.checked: ${currentLabel.checked}`);
console.log(`label: ${label}`);
return {
label,
checked: currentLabel ? currentLabel.checked : true,
};
});
});
}, [savedEvents]);