Last active
January 25, 2016 05:20
-
-
Save dydx/66ddf02bf2325f647445 to your computer and use it in GitHub Desktop.
I kinda like this syntax a lot more than the class syntax
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
var todos = ["Learn React", "Make a Cool Thing", "Retire Early"]; | |
// This is our top-level Component, we render this | |
const TodosComponent = props => { | |
const Todos = renderTodos(props.todos); | |
return ( | |
<ul> | |
{ Todos } | |
</ul> | |
); | |
}; | |
// this is a mapping function that takes a list | |
// and applied a render function over each item | |
const renderTodos = todos => ( | |
todos.map(todo => renderTodo(todo)) | |
); | |
// simply take a single item and render it | |
const renderTodo = todo => ( | |
<li>{todo}</li> | |
); | |
// Apply our top-level component with its props | |
// and attach to an existing DOM node | |
ReactDOM.render( | |
<TodosComponent todos={todos} />, | |
document.getElementById('container') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment