Answer the question
In order to leave comments, you need to log in
How to display variables from componentDidMount?
How do I display artistname and title in the second componentDidMount? Because now the value is not passed.
async componentDidMount() {
const url = "https://api.laut.fm/station/city/current_song";
const response = await fetch(url);
const data = await response.json();
this.setState({ info: data });
const artistname = this.state.info.artist.name;
const title = this.state.info.title;
}
async componentDidMount() {
const image = "http://ws.audioscrobbler.com/2.0/?method=album.getInfo&artist=" + artistname + "&album=" + title + "&api_key=SECRET_KEY&format=json";
const images = await fetch(image);
const dataimage = await images.json();
this.setState({ cover: dataimage });
console.log(dataimage);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question