Want to assign refs to multiple components. You should use ref callback instead of ref and also yes you need multiple refs, an array should be good.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
constructor() { super(); this.btn = []; } onRunClick(act, index, e) { this.btn[index].setAttribute("disabled", true); } render () { return ( <div> { this.state.acts.map((act, index) => { let boundActRunClick = this.onRunClick.bind(this, act, index); return ( <p key={act._id}> Name: {act.name}, URL(s): {act.urls} <button ref={(ref) => this.btn[index] = ref} onClick={boundActRunClick}>Run</button> </p> ) }) } </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.