SHARE
TWEET

parent

yogasmara May 27th, 2020 715 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2.  
  3. import Back from './single-page/back.component';
  4. import DataCard from './single-page/data-card.component';
  5.  
  6. const API_KEY = process.env.REACT_APP_API_KEY;
  7.  
  8. class SingleComponent extends Component {
  9.  
  10.   state = {
  11.     movieSingle: []
  12.   }
  13.  
  14.   componentDidMount() {
  15.     let id = this.props.match.params.id;
  16.     const ENDPOINT_SINGLE_MOVIE = `https://api.themoviedb.org/3/movie/${id}?api_key=${API_KEY}&language=en-US`;
  17.  
  18.     fetch(ENDPOINT_SINGLE_MOVIE)
  19.       .then(res => res.json())
  20.       .then((data) => {
  21.         this.setState({
  22.           movieSingle: data
  23.         })
  24.       })
  25.       .catch(console.log);
  26.   }
  27.  
  28.  
  29.   render() {
  30.     return (
  31.       <div>
  32.         <Back />
  33.         <DataCard movieSingle={this.state.movieSingle} />
  34.       </div>
  35.     )
  36.   }
  37. }
  38.  
  39. export default SingleComponent;
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