Skip to content

Instantly share code, notes, and snippets.

@benkissi
Last active April 15, 2019 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkissi/adb2eaf73d6b40bf4a4c750b32990049 to your computer and use it in GitHub Desktop.
Save benkissi/adb2eaf73d6b40bf4a4c750b32990049 to your computer and use it in GitHub Desktop.
Context blog
const DisplayTodos = props => {
return (
<AppConsumer>
{({ todos, completed }) => {
const notCompleted = todos.filter(todo => {
if (todo.completed === false) {
return todo;
}
});
return (
<div>
<p>All your todos: {notCompleted.length}</p>
<ol>
{todos.length > 0
? todos.map(todo => (
<li
className={
todo.completed
? "completed todo align-left"
: "todo align-left"
}
key={todo.id}
onClick={() => completed(todo.id)}
>
{todo.todo}
{" "}
<span className={todo.completed ? "date" : "date"}>
{new Date(todo.createdAt).toString()}
</span>
</li>
))
: ""}
</ol>
</div>
);
}}
</AppConsumer>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment