Cómo actualizar la matriz dentro del componente de función de estado de uso de la matriz, la matriz está dentro de setTask() y cómo usar setTask() y agregar new_photo en las fotos
const new_photo = "testing2.png"; <------------ insert this value in photos const [task, setTask] = useState([ { task_id: 123, title: "sample", photos: ["testing1.png"] <------------ here } ])El resultado debería ser así:
[ { task_id: 123, title: "sample", photos: ["testing1.png","testing2.png"] } ] const new_photo = "testing2.png"; // <------------ insert this value in photos const [task, setTask] = useState([ { task_id: 123, title: "sample", photos: ["testing1.png"] // <------------ here } ]) const arrayPush = (ID) => { setTask((element) => { element.forEach((e) => { if (e.task_id === ID) { e.photos.push(new_photo); } }); }); console.log(task); } const arrayPush2 = (ID) => { let taskCopy = Array.from(task) taskCopy.forEach((element) => { if (element.task_id === ID) { element.photos.push(new_photo); } }); setTask(taskCopy) }; arrayPush(123) arrayPush2(123)setTask((oldTasks) => { const myTask = oldTasks.find(t => t.task_id === 123) return [ ...oldTasks.filter(ot => ot.task_id != 123), { ...myTask, photos: [...myTask.photos, new_photo], } ] })Ref: operador de propagación y actualización de estado asíncrono