I'm struggling to understand a piece of code related to handling an onClick event in JavaScript/React. Here is the function:
handleButtonClick(key, song) {
return () => {
document.getElementById(key).play();
this.setState({
currentSongText: song,
});
};
}
I'm confused about why it uses return () =>{} inside the body of handleButtonClick. If I remove it, the code stops working. I couldn't find any information on this while searching online, so any advice would be appreciated.
Here's the link to the project: https://codepen.io/koffiekan/pen/eYJqdWW