2017-02-24 10 views

回答

2

目前我不認爲有一個屬性設置爲reflux-Field s將其設置爲默認激活狀態。一旦組件被安裝,你可以通過引用來設置它。

編輯:這可能是使用getRenderedComponent()

componentDidMount() { 
    this.refs.defaultInput 
    .getRenderedComponent() 
    .focus() 
} 

<Field name="defaultInput" ref="defaultInput" withRef component="input"/> 

From redux-form Github一個更清潔的實現還有一些其他的例子,鏈接在Github的問題。

+0

嘗試瞭解決方案以及閱讀引用的Redux-Form Github問題,但仍無法使其工作。儘管使用了上面的代碼,但是this.refs.defaultInput在componentDidMount中未定義。 –

+0

您是使用自定義輸入組件還是標準「輸入」? –

+0

自定義輸入。你可以查看我在這裏嘗試的代碼:http://stackoverflow.com/questions/42459190/how-to-use-react-refs-to-focus-a-redux-form-field –

相關問題