I'm trying to count how many existing elements there are in all columns within taskIds. Not sure what the most efficient way to do this as I am already mapping data in the return statement. I want to be able to pass the total number in CustomHeader. Expected value should return 5
I have this component:
const Example = () => {
const [state] = useContext(DataContext);
const count = 0;
return (
<>
<div
title={<CustomHeader title="Things to do" size="18px" count={count} />}
>
{state.columnOrder.map(columnId => {
const column = state.columns[columnId];
const tasks = column.taskIds.map(taskId => state.tasks[taskId]);
return <Item key={column.id} column={column} tasks={tasks} />;
})}
</div>
</>
);
};
export default Example;
and this is my DataContext:
tasks: {
"task-1": { id: "task-1", description: "Test" },
...
},
columns: {
"column-1": {
id: "column-1",
taskIds: ["task-1", "task-2", "task-3", "task-4"]
},
"column-2": {
id: "column-2",
title: "column-2",
taskIds: ["task-5"]
},
"column-3": {
id: "column-3",
title: "column-3",
taskIds: []
}
},
columnOrder: ["column-1", "column-2", "column-3"]
};