Created
October 11, 2018 10:48
-
-
Save anandof28/47d739f758c2f418f5b5806ff2a5b17b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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