I am building a Film grid that return their Id, thumbnail, title, episode number and released date. The onClick events of "Details" are already binded to the :id_film url.
How can I display the correct Film Object Values on each specific view e.g: all species.names?
CodeSandbox Demo & Api Documentation Swapi
DetailFilms.js Component:
import React, { Component } from 'react';
import axios from 'axios';
import { Link } from 'react-router-dom';
class DetailFilms extends Component {
state = {
film: null
}
componentDidMount() {
let id = this.props.match.params.films_id;
axios.get('https://swapi.co/api/films/' + id)
.then(res => {
this.setState({
film: res.data
})
console.log(res)
})
}
render() {
const film = this.state.film ? (
<div className="jumbotron">
<h2 className="display-4">{this.state.film.title}</h2>
<p className="lead">{this.state.film.director}</p>
<hr className="my-4" />
<p>{this.state.film.producer}</p>
<p>Episode Nº: {this.state.film.episode_id}</p>
<p className="font-italic">{this.state.film.opening_crawl}</p>
<p>Species: {this.state.film.species}</p>
<Link className="btn btn-primary btn-lg" to="/" role="button">Learn more</Link>
</div>
) : (
<div className="spinner-border" role="status">
<span className="sr-only">Loading...</span>
</div>
)
return (
<div className="d-flex justify-content-center align-items-center ">
{film}
</div>
)
}
}
export default DetailFilms;