Last active
August 23, 2023 12:40
-
-
Save EmmanuelObua/abb414612b8bb3dd979d1bc4b670d01b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { TaskConsumer } from './TaskContext'; | |
function TaskList() { | |
// Here we are actually distructing the tasks and dispatch methods from the TaskConsumer which has the | |
// taskContext object. | |
return ( | |
<TaskConsumer> | |
{({ tasks, dispatch }) => ( | |
<> | |
{tasks.map(task => ( | |
<div key={task.id} className="d-flex justify-content-between p-1"> | |
<input type="checkbox" checked={task.completed} | |
onChange={() => dispatch({type: 'UPDATE_TASK', payload: { id: task.id, completed: !task.completed } }) } | |
/> | |
{task.title} | |
{!task.completed && ( | |
<button className="btn btn-sm btn-danger" style={{ borderRadius:100 }} onClick={() => dispatch({ type: 'DELETE_TASK', payload: task.id }) }>X</button> | |
)} | |
</div> | |
))} | |
</> | |
)} | |
</TaskConsumer> | |
); | |
} | |
export default TaskList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment