If you want to retrieve dynamic child key upon event in React? Partially apply the function callback by using JavaScript’s native bind. This is mentioned in React’s “Communicate Between Components” doc:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | callbackFn: function(key) { // key is "result.id" this.props.callbackFn(key); }, render: function() { var results = this.props.results; return ( <div> {results.map(function(result) { return ( <ChildComponent type="text" key={result.id} changeCallback={this.callbackFn.bind(this, result.id)} /> ); }, this)} </div> ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.