my question is how to make an event a click pull out an item from a json in particular, that every time a click on a name appears the same name
If I click on value: 1 send me the same name in a log and I could not get it
My code is as follows
class App extends Component {
constructor(props){
super(props);
this.state = {
names: []
};
axios.get("http://localhost:3001/names")
.then(response => {
this.setState({
names: response.data
})
})
.then(error => {
console.log(error);
})
}
handleClick = (name) => {
console.log('this is:', {name} );
}
render() {
return (
<div>
<ul>
{
this.state.names.map( name =>
<li key={name} onClick={this.handleClick}>{name}</li>)
}
</ul>
</div>
);
}
}