div 요소는 value 속성이없는, 그래서 아무것도 특정 클릭에 대한 이벤트 객체의 뒷면에 통과 할 수 없습니다 :
searchForArtist(query) {
request.get(`https://api.spotify.com/v1/search?q=${query}&type=artist`)
.then((response) => {
const artist = response.body.artists.items[0];
const name = artist.name;
const id = artist.id;
const img_url = artist.images[0].url;
this.setState({
selectedArtist: {
name,
id,
img_url,
},
});
})
.then(() => {
this.getArtistAlbums();
})
.catch((err) => {
console.error(err);
});
}
getSubsequentCollabs(artist) {
this.setState({
selectedArtist: {},
selectedAlbums: {},
artistCounts: {},
});
console.log(artist);
this.searchForArtist(artist);
}
artistOnClick(e) {
console.log(e);
let artist = e.target.value;
this.getSubsequentCollabs(artist);
}
나는 또 다른 구성 요소가이 일을 가지고 행사.
이 일어날 기대에 따라 같은 일을하여 해결할 수 :
const Artist = ({name, artistOnClick}) => {
return (
<div onClick={() => artistOnClick(name)}>
{name}
</div>
)
}
export default Artist;
'div'구성 요소 'onclick'이벤트를 듣고 있습니다. 'e.target.value'에 무엇을 기대합니까?! –
죄송합니다. 더 자세히 설명하거나 조금 도와 주실 수 있습니까? 나는 너만큼 많은 경험을하지 못할 수도있다. – Mshark
다른 해결책은 ... 'e.nativeEvent.target.name'입니다. –