i am doing an axios call and the data i receive is array of objects from the backend inside each of which contains a value called result(format - result:"Hello"). There is a button which when clicked should go to the particular index and fetch the value of result specified and pass it . Not sure how exactly to accomplish this .
componentDidMount(){
let payload = this.props.location.state
axios.post(`http://localhost:8200/service/${this.service_name}/requests`,payload)
.then( response=>{
console.log(response.data.methods)
this.setState({
methods:response.data.methods,
trace:response.data.methods[0].result
// Here above i have written ,but it only fetches from index[0] statically ,
i want it to select the result of the particular button i press.
});
})
}
playitHandler(){
let payload = {
"service_name":this.service_name,
"trace_id":this.state.trace
}
}
<button className="btn btn-primary" onClick={()=>this.playitHandler()}>Display</button>
Tried passing index to ComponentDidMount(){} , i guess we cant pass it there , since it threw an error .