daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2.  
  3. export default class App extends Component {
  4.  
  5.   constructor(props) {
  6.     super(props);
  7.     this.state = { shows: [], };
  8.   }
  9.  
  10.  
  11.   componentDidMount() {
  12.     fetch('https://api.infinum.academy/api/shows')
  13.       .then((data) => data.json())
  14.       .then((response) => {
  15.         let shows = response.data.map((show) => {
  16.           return (
  17.             <div key={show._id}>
  18.               <h3>{show.title}</h3>
  19.               <br />
  20.               <h6>Description :</h6>
  21.               <p>{this.showDetails(show._id)}</p>
  22.               <h6>Episodes :</h6>
  23.                 {this.showEpisodes(show._id)}
  24.             </div>
  25.           )
  26.         })
  27.         this.setState({ shows: shows });
  28.       })
  29.   }
  30.  
  31.   showDetails(showId) {
  32.     fetch(`https://api.infinum.academy/api/shows/${showId}`)
  33.       .then((data) => data.json())
  34.       .then((response) => {
  35.         return (
  36.           response.data.description
  37.       )
  38.       })
  39.   }
  40.  
  41.   showEpisodes(showId) {
  42.     fetch(`https://api.infinum.academy/api/shows/${showId}/episodes`)
  43.     .then((data) => data.json())
  44.     .then((response) => {
  45.       return (
  46.         <p>{response.data}</p>
  47.       )
  48.     })
  49. }
  50.  
  51.  
  52.   render() {
  53.     console.log(this.state.shows);
  54.     return (
  55.  
  56.       <div className="container">
  57.         <h1 id='title'>
  58.           TV shows!
  59.       </h1>
  60.         <div className='showsContainer'>
  61.           {this.state.shows}
  62.         </div>
  63.       </div>
  64.  
  65.  
  66.     );
  67.   }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top