It’s working as expected but it doesn’t give an error when trying to print the array
What’s a better way to print the array I have in state?
{this.state.op} that how I am printing it but it doesn’t show anything
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
items: myData,
op:[]
};
}
handleClick(element) {
console.log('The button was clicked.');
console.log(element);
this.state.op.push(element);
console.log(this.state.op);
}
render () {
return (
<div>
{
Object.keys(this.state.items).map(key => {
return <button onClick={this.handleClick.bind(this,this.state.items[key])}> {key} - {this.state.items[key]}</button>
})
}
{this.state.op} //here
</div>
)
}
}
export default App;