So I mapped an array to buttons having the value to be the element of the array, but when I log the event.target.value to the console, I get undefined sometimes.
When I click each button, I get this in the console
0
1
2
3
undefined
undefined
undefined
6
7
undefined
9
Here's the code I have
class App extends Component {
constructor(props) {
super(props)
this.state = {
selected: '',
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}
}
handleClick = (event) => {
event.preventDefault()
console.log(event.target.value);
}
render() {
return (
<div>
<Container>
<Row>
{this.state.numbers.map(i => {
return (
<Col key={i.toString()}>
<ButtonToolbar>
<Button
value={i}
onClick={this.handleClick}
>
<h3>{i}</h3>
</Button>
</ButtonToolbar>
</Col>
)
})}
</Row>
</Container>
</div>
);
}
}