const [columns, setColumns] = useState({
Configured: {
progress: "Configured",
tasks: [],
},
Approved: {
progress: "Approved",
tasks: [],
},
AwaitingPO: {
progress: "Awaiting PO",
tasks: [],
},
InProduction: {
progress: "In-Production",
tasks: [],
},
Delivered: {
progress: "Delivered",
tasks: [],
},
});
const { loading, error, data } = useQuery(GET_CUSTOMERS);
useEffect(() => {
if (data) {
data.customer.map((item) => {
setColumns({
...columns,
[item.progress]: {
...columns[item.progress],
tasks: [
...columns[item.progress].tasks, ///Spread operator not working here
item
],
},
});
});
}
}, [data]);
I am trying to add several objects named item to my tasks array. Out of the three items I have, only one is being added. Nested states seems to be quite hard, and I feel like I'm doing something wrong regarding useEffect or the map function itself.