Skip to content

Instantly share code, notes, and snippets.

@dydx
Last active January 25, 2016 05:20
Show Gist options
  • Save dydx/66ddf02bf2325f647445 to your computer and use it in GitHub Desktop.
Save dydx/66ddf02bf2325f647445 to your computer and use it in GitHub Desktop.
I kinda like this syntax a lot more than the class syntax
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