Hello campers,
I’m starting the drum machine project, making a map of the component tree I’ll need, it looks like this:
main
---tempo
---launch
---pads
---pad1
---pad2
---pad3
---pad4
---pad5
---pad6
---pad7
---pad8
---pad9
---sequencer
---sixteenth1
---sixteenth2
---etc
I’m beggining to understand a React component structure, however I don’t really understand how to do with the many pads or sixteenth elements. I would like for the pads to be generated from one unique class and pass their index via a prop. I’m not sure how to do to get each of my pad having a different action.
I want to store the states of my pads in the main component so that the sequencer can access them, the state would look like this:
main.state.pad = [
{
index: 1,
focus: 1,
sequencer: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
},
{
index: 2,
focus: 0,
sequencer: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
},
etc
];
I’m looking for the proper method to do this, I was thinking of using conditonal rendering depending on the index prop passed when generating the pads. Then use this index to modify main.state.pad[index].
Is this a good way of thinking in react? I would like to know if you have some advice, thank you!