Skip to content

Instantly share code, notes, and snippets.

@ccjoel
Created June 23, 2019 22:43
Show Gist options
  • Save ccjoel/bd5d2096b2e4d722730c61f25ff58a3d to your computer and use it in GitHub Desktop.
Save ccjoel/bd5d2096b2e4d722730c61f25ff58a3d to your computer and use it in GitHub Desktop.
react examples for a friend
/** Assume database returns data for tasks, we may
* model each task as an object, and use React for the view.
**/
/**
* Simple component that accepts data for a task, and returns markup for it
**/
function Task({name, finished, reminderDateTime, dueDate}) {
return (
<fieldset>
<legend>
<input
type="checkbox"
checked={finished} />
&nbsp; Task: {name}
</legend>
Remind me on: {reminderDateTime}<br>
Due Date: {dueDate}
</fieldset>
);
}
/**
* An array of tasks. Each task is a js object like:
* {
* name: "call my friend",
* finished: true,
* reminderDateTime: null, // its finished, no remind time set
* dueDate: Date obj
* }
**/
function TodoList(tasks) {
return (
<ul>
{tasks.map(task => <li> <Task {...task} /> </li>)}
</ul>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment