Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created May 25, 2017 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackfranklin/623ae418f9cad0edc4146513720fe186 to your computer and use it in GitHub Desktop.
Save jackfranklin/623ae418f9cad0edc4146513720fe186 to your computer and use it in GitHub Desktop.
const User = props => <p>This would render a user</p>
class Users extends React.Component {
// has this.state.users which is an array from an API
// not gonna bother writing the code to fetch that...
render() {
return (
<div>
<h2>The users</h2>
<ul>
{this.state.users.map(u => (
<li key={u.id}><User user={user} /></li>
))}
</ul>
</div>
)
}
}
// vs...
class Users extends React.Component {
// has this.state.users which is an array from an API
// not gonna bother writing the code to fetch that...
renderUsers() {
this.state.users.map(u => (
<li key={u.id}><User user={user} /></li>
))
}
render() {
return (
<div>
<h2>The users</h2>
<ul>{this.renderUsers()}</ul>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment