I'm beginner in ReactJS. I add HTML code in a div and this HTML code is for buttons, it's works, but the onClick attribute is always undefined. I tried two things but it doesn't work.
First try :
const createListPlaylist = (res) => {
if (res === undefined)
return;
var list = "";
for (let i = 0; i < res.data.items.length; i++)
list += `<Button onClick=${createPlaylistWidget(res.data.items[i].id)}>${res.data.items[i].name}</Button><br>`;
document.getElementById("PlayListViewer").innerHTML += list;
}
Second try :
const createListPlaylist = (res) => {
if (res === undefined)
return;
var list = "";
var listArray = [];
for (let i = 0; i < res.data.items.length; i++) {
listArray.push(createPlaylistWidget(res.data.items[i].id));
list += `<button onClick=${displayPlaylitSelected(listArray[i])}>${res.data.items[i].name}</button><br>`;
}
document.getElementById("PlayListViewer").innerHTML += list;
}
Result :
createListPlaylist is called after an axios request and the res parameter is the response of the request and yes res.data.items[i].id is correct I can print in in the console with no problem. So, ask your help because I don't no why my onClick attribute is undefined and I don't find the answer.
Thank you in advance for the answers.
