0

I have buttons created in a loop. Each contains a key and data-id property.
I want to onClick pass the key or data-id to the called function. I experimented a few things, but none worked. Here is the code.

buttonPress: function (path,type,period) {
    AppActions.moveToPage(path,{type:type},period);
},



<div key={$key} data-id={$key} style={{textAlign: 'center'}} onClick={() => this.buttonPress("Listing",this.props.id, this.state.filters)}>{this.state.Graph?this.state.diagnosisGraph[key]:<img src={AppApi.baseUrl + 'img/loading.gif'} />}</div>
1
  • 1
    Why not just pass $key to this.buttonPress function? Commented Jan 12, 2018 at 13:08

1 Answer 1

1

you can directly pass the $key to the mouse down function

buttonPress: function (path,type,period,key) {
AppActions.moveToPage(path,{type:type},period);
},



<div key={$key} data-id={$key} onClick={() => this.buttonPress("Listing",this.props.id, this.state.filters, key)}>{this.state.Graph?this.state.diagnosisGraph[key]:<img src={AppApi.baseUrl + 'img/loading.gif'} />}</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.