I am building a React app using the Last.fm API. They have used a # tag in the key for the artist image url's, see below. Unfortunately the # is crashing React. I have searched the web and can find nothing on how to escape this character. The "size" key works O.K.
image
:
Array(6)
0
:
{#text: "https://lastfm-
img2.akamaized.net/i/u/34s/4b89e84da385d17e6b46c489f46d4522.png",
size:
"small"}
1
:
{#text: "https://lastfm-
img2.akamaized.net/i/u/64s/4b89e84da385d17e6b46c489f46d4522.png",
size:
"medium"}
..........................
The React code is below:
import React, { Component } from 'react';
import './App.css';
import Title from './components/Title.js';
import Form from './components/Form.js';
import Music from './components/Music.js';
const API_KEY = '.....';
//const SECRET = '......';
class App extends Component {
state = {
name: undefined,
bio: undefined,
listeners: undefined,
image: undefined,
error: undefined
}
getMusic = async (e) => {
e.preventDefault();
const name=e.target.elements.artist.value;
const api_call = await fetch(`http://ws.audioscrobbler.com/2.0/?
method=artist.getinfo&artist=${name}&api_key=${API_KEY}&format=json`)
const data = await api_call.json();
console.log(data);
this.setState({
name: data.artist.name,
bio: data.artist.bio.summary,
image: data.artist.image[1]#text,
error: ""
});
}
render() {
return (
<div className="App">
<Title />
<Form getMusic={this.getMusic}/>
<Music name={this.state.name}
bio={this.state.bio}
image={this.state.image}
error={this.state.error}
/>
</div>
);
}
}
export default App;
Can anyone assist?