ReactJS: get button ‘value’ on click

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’)

Answer

I believe you should have access to the brand value by doing this:

onClick: () => {console.log(brand)}}

Since the value of brand is accessing within the .map() you are doing