Tell us what’s happening:
Hi,
So I facing difficulty in creating an a set of buttons using the map method. What I have done is create an array of objects with the button id, src etc and would like to map this array on to my buttons.
Here’s my code so far:
import React from “react”;
import ReactDom from “react-dom”;
const sounds = [
{
idnum: “1”,
id: “Q”,
src: “1.html”,
},
{
idnum: “1”,
id: “W”,
src: “”,
},
{
idnum: “1”,
id: “E”,
src: “”,
},
{
idnum: “1”,
id: “A”,
src: “”,
},
{
idnum: “1”,
id: “S”,
src: “”,
},
{
idnum: “1”,
id: “D”,
src: “”,
},
{
idnum: “1”,
id: “Z”,
src: “”,
},
{
idnum: “1”,
id: “X”,
src: “”,
},
{
idnum: “1”,
id: “C”,
src: “”,
},
];
class Button extends React.Component {
constructor(props) {
super(props);
}
render() {
const buttonData = this.sounds.map((info) => (
<button>
{info[id]}+{info[idnum]}
</button>
));
return { buttonData };
}
}
export default Button;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Build a Drum Machine
Link to the challenge: