Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. import React from 'react';
  4. import AuthorAPI from '../../api/authorApi';
  5.  
  6. class Authors extends React.Component {
  7.     constructor() {
  8.         super()
  9.         this.state = {
  10.             authors: []
  11.         }
  12.     };
  13.  
  14.     componentWillMount() {
  15.         this.setState({ authors: AuthorAPI.getAllAuthors() });
  16.     };
  17.  
  18.     render() {
  19.         let createAuthorRow = (author) => {
  20.             return (
  21.                 <tr key={author.id}>
  22.                     <td><a href={"/#authors/" + author.id}>{author.id}</a></td>
  23.                     <td>{author.firstName} {author.lastName}</td>
  24.                 </tr>
  25.             );
  26.         };
  27.  
  28.         return (
  29.             <div>
  30.                 <h1>Authors</h1>
  31.  
  32.                 <table className="table">
  33.                     <thead>
  34.                         <th>ID</th>
  35.                         <th>Name</th>
  36.                     </thead>
  37.                     <tbody>
  38.                         {this.state.authors.map(createAuthorRow, this)}
  39.                     </tbody>
  40.                 </table>
  41.             </div>
  42.         );
  43.     };
  44. }
  45.  
  46. export default Authors;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement