Here I am trying to render my tasks' titles in a list. But for some reason they don't render. Here is the MyTasks
component:
const MyTasks = (props) => {
const tasks = [...props.tasks];
console.log(props.tasks, "props.tasks");
console.log(tasks, "tasks");
console.log(tasks[0], "tasks[0]");
return (
<ListGroup className="mx-2 mt-4">
{tasks.map((task) => {
return <ListGroup.Item key={task.id}>{task.title}</ListGroup.Item>;
})}
</ListGroup>
);
};
export default MyTasks;
I tried console.log
inside the component but for some reason I can't access the array elements but I can view the props.tasks
array.
In my TaskLists
component I am rendering the MyTasks
component.
TaskLists
component is using a useState hook for updating the tasks
prop value of the MyTasks
component but during the child component re-render I am not able to access the elements in the props.tasks
array.
const TaskList = () => {
const [tasks, setTasks] = useState([]);
const getTasks = () => {
//code to get tasks data from data base
setTasks(taskList);
};
return (
<ListGroup className="mx-2 mt-4">
<MyTasks tasks={tasks} />
</ListGroup>
);
};
Here is my console.log
screenshot, I cant access the array elements for some reason.