Created
June 23, 2019 22:43
-
-
Save ccjoel/bd5d2096b2e4d722730c61f25ff58a3d to your computer and use it in GitHub Desktop.
react examples for a friend
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
/** 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} /> | |
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