Created
September 8, 2019 10:03
-
-
Save ridoansaleh/e4a5f3c10ca2479ac53880cf4ff2b4a3 to your computer and use it in GitHub Desktop.
This file contains 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, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { Link } from 'react-router-dom'; | |
import axios from 'axios'; | |
import { Navbar } from '../components/Navbar'; | |
import { API_BASE_URL } from '../constant'; | |
class Book extends Component { | |
static propTypes = { | |
match: PropTypes.object, | |
}; | |
constructor() { | |
super(); | |
this.state = { | |
book: {}, | |
}; | |
} | |
componentDidMount() { | |
const ID = this.props.match.params.id; | |
axios | |
.get(API_BASE_URL + '/books/' + ID) | |
.then(res => { | |
this.setState({ | |
book: res.data, | |
}); | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
} | |
render() { | |
const { book } = this.state; | |
return ( | |
<div> | |
<Navbar /> | |
<p className="breadcrumbs"> | |
<Link to="/">Home</Link> / {book.title} | |
</p> | |
<section className="book-detail-container"> | |
<div className="book-detail-cover-wrapper"> | |
<img className="book-detail-cover-image" src={book.cover} /> | |
</div> | |
<div className="book-detail-misc"> | |
<p className="book-detail-title">{book.title}</p> | |
<p>{book.author}</p> | |
<p>{book.description}</p> | |
</div> | |
</section> | |
</div> | |
); | |
} | |
} | |
export default Book; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment