可以說,我有下面的代碼在我的反應成分三級深<Foo><Bar><InputBox/><Bar></Foo>
其中「的InputBox」是一個演示組件如何在組件層次結構中訪問輸入值?
<input type="text" id="inputBox" ref="inputBox" name="inputBox" value={this.state.inputVal} onChange={this.handleChange} />
我想獲得的輸入值在我的容器組件來執行的形式驗證。我可以用香草味JS
document.getElementById('inputBox').value
或使用陣營裁判得到的值(但是,當我的裁判是非常深刻的下方一個不工作)
this.refs.inputBox.value
我想知道哪種方法在性能方面更好,爲什麼?並想知道如何使用React的ref方法訪問組件層次結構深處的輸入值?
的[findDOMNode可能的複製VS的getElementById用於普通DOM元素](http://stackoverflow.com/questions/36415198/finddomnode-vs-getelementbyid-for-plain-dom-elements) – Miah
@Miah我現在更新了這個問題 –