I have a component that creates buttons with information from an array, when the user clicks on the button I want to pass the information from this array to a function, but I'm getting '[Object Object]', how do I pass the array and access the elements in the function?
Function:
handleClick (e) {
const { value } = e.currentTarget
console.log(value)
};
Component render:
render () {
return (
<div>
{this.state.enrollments.map(item => (
<div key={item.id}>
<button value={item} onClick={this.handleClick}>
{item.enrollment}
</button>
</div>
))}
</div>
)
}
Array passed to map:
0: {id: 1, evaluation_flag: false, enrollment: "2019.1", user_id: 2}
1: {id: 2, evaluation_flag: false, enrollment: "2019.2", user_id: 2}
In the handleClick function I want to access the values, type: value.id or value.user_id.