Hi everyone before too late and hours, i can't work .
I need update each checkBox, when this is true or false (tasks array are checkBox in front End)
Data seeds
const datas = [
{
id: 10,
name: job01,
tasks: [
{ name: "morning", value: false },
{ name: "afternoon", value: true },
{ name: "sunset", value: false },
{ name: "night", value: true },
],
completed: false
}];
the next code to update data, when press one checkbox is:
const [todos, setTodos] = useState(datas)
const toggleTask = taskId => {
const updateTodos = todos.forEach(to => {
to.tasks.forEach(task => {
if (taskId === to.name)
console.log('update datas: ', { ...task, value: !task.value})
}
})
})console.log('Result: ', updateTodos ) };//only show undefined
Thnz for readme.