I'm making a React Axios Project with https://swapi.dev/api/films/, the characters data shows another API link so I make an Axios loop to show characters name. The characters name can show in console, so it should be success but the name is not showing on the screen. Already return the data but still not showing.
This is the web app picture:
This is the full code:
import React, { Component } from "react";
import axios from "axios";
class MovieDetail extends Component {
state = {
showMovieDetail: false,
};
movieListClicked = () => {
this.setState({ showMovieDetail: !this.state.showMovieDetail });
};
getCharactersDetails = () => {
const charsAPILink = this.props.characters;
const charData = return charsAPILink.map((data) => {
axios.get(data).then((response) => {
console.log(response.data.name);
return response.data.name;
});
});
return charData;
};
render() {
return (
<div className="MovieDetail" onClick={this.movieListClicked}>
{!this.state.showMovieDetail ? (
<h2>{this.props.title}</h2>
) : (
<div>
<h3>
Title : {this.props.title} <br />
Episode : {this.props.episode} <br />
{this.props.opening} <br />
Director : {this.props.director} <br />
Producer : {this.props.producer} <br />
Date : {this.props.date} <br />
Characters : {this.getCharactersDetails()}
</h3>
</div>
)}
</div>
);
}
}
export default MovieDetail;
