Skip to content

Instantly share code, notes, and snippets.

@anandof28
Created October 11, 2018 10:48
Show Gist options
  • Select an option

  • Save anandof28/47d739f758c2f418f5b5806ff2a5b17b to your computer and use it in GitHub Desktop.

Select an option

Save anandof28/47d739f758c2f418f5b5806ff2a5b17b to your computer and use it in GitHub Desktop.
import React from "react";
import { render } from "react-dom";
import "bootstrap/dist/css/bootstrap.css";
import { USERS } from "./mock-data/users";
class UserList extends React.Component {
state = {
users: USERS,
selectedUser: {}
};
//Not listener function: normal biz api
onSelect = user => {
console.log(user);
this.setState(() => {
return {
selectedUser: user
};
});
};
render() {
return (
<div className="container">
<nav>
<h1>User List App</h1>
</nav>
<hr />
<ul>
{this.state.users.map((user, index) => {
return (
<li
onClick={() => {
this.onSelect(user);
}}
key={index}
>
{user.name}
</li>
);
})}
</ul>
<h4>User Details</h4>
<div>
{this.state.selectedUser.email}
</div>
</div>
);
}
}
render(<UserList />, document.getElementById("root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment