I'm creating buttons using map to loop over an array. Each button is an item in the array. I'm also using React.createElement to create each button.
['NICK', 'NKJR', 'NKTNS'].map(function (brand) {
return React.createElement('button', {
onClick: (e) => { console.log(e.target) }
}, brand)
})
..however, for the onClick listener, how do I pass in the 'value' for each button?
For example, I'm trying to get the console.log to log 'NICK', 'NKJR' or 'NKTNS' depending on which button is clicked. Right now when I click a button it just logs <button>NICK</button> for example (I want 'NICK')
brandis already in scope of your click handler definition so why not just directly use it? Otherwise, you could usee.target.textContentore.target.valuethough YMMV on that last one if you don't also directly assignvalue: brand