Skip to content

Instantly share code, notes, and snippets.

@panzerdp
Created July 8, 2017 07:56
Show Gist options
  • Save panzerdp/9cb1f68eded62db500f8d4aa2c3d1264 to your computer and use it in GitHub Desktop.
Save panzerdp/9cb1f68eded62db500f8d4aa2c3d1264 to your computer and use it in GitHub Desktop.
Extract user data to component map method
class App extends React.Component {
//....
render() {
return (
<div>
<h1>Users</h1>
<ul>
{this.state.users.map(this.userDataToComponent)}
</ul>
</div>
);
}
userDataToComponent = user => {
return (
<UserListItem
key={user.id}
user={user}
onClick={this.deleteUser}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment