Skip to content

Instantly share code, notes, and snippets.

@slorber
Last active November 17, 2016 17:10
Show Gist options
  • Save slorber/27447ab86ac61ddb229d4108e521c861 to your computer and use it in GitHub Desktop.
Save slorber/27447ab86ac61ddb229d4108e521c861 to your computer and use it in GitHub Desktop.
Use do { } makes React render() method more readable
// FP languages permit to evaluate if/else expressions as values.
// In many cases it permits to avoid using mutable variables (var/let), multiple returns, or nested ternary operators
// This is the do { } notation (stage 0), that permits to write the following right now with Babel.
const Users = ({users}) => (
<div>
{users.map(user =>
<UserCard key={user.id} user={user}/>
)}
</div>
)
const UserList = ({users}) => do {
if (!users) <div>Loading</div>
else if (!users.length) <div>Empty</div>
else <Users users={users}/>
}
@gre
Copy link

gre commented Jul 19, 2016

can't wait pattern matching :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment