Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import CourseDataService from "../Service/CourseDataService";
  3.  
  4.  
  5. class ListCoursesComponent extends Component{
  6.     constructor(props) {
  7.         super(props);
  8.         this.state = {
  9.             courses: [],
  10.             message: null
  11.         }
  12.         this.refreshCourses = this.refreshCourses.bind(this)
  13.     }
  14.     componentDidUpdate(){
  15.         console.log(this.state.courses);
  16.     }
  17.     componentDidMount() {
  18.         this.refreshCourses();
  19.     }
  20.     refreshCourses(){
  21.         CourseDataService.retrieveDataFromApi()
  22.         .then(response => {
  23.             console.log(response.data);
  24.             this.setState({courses : response.data});
  25.         })
  26.     }
  27.     render(){
  28.         return(
  29.             <div className="container">
  30.                 <h3>All Courses</h3>
  31.                 <div className="container">
  32.                     <table className="table">
  33.                         <thead>
  34.                             <tr>
  35.                                 <th>Id</th>
  36.                                 <th>Description</th>
  37.                             </tr>
  38.                         </thead>
  39.                         <tbody>
  40.                             {
  41.                                 this.state.courses.map(
  42.                                     course =>
  43.                                         <tr key={course.id}>
  44.     <td>{course.id}</td>
  45.                                 <td>{course.description}</td>
  46.  
  47.                                         </tr>
  48.                                 )
  49.                             }
  50.                         </tbody>
  51.                     </table>
  52.                 </div>
  53.             </div>
  54.         )
  55.     }
  56. }
  57.  
  58. export default ListCoursesComponent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement