2016-08-15 25 views
3

我有一個與TextField在它反應組分:材料的UI的TextField與之反應-終極版搞亂

<TextField 
    hintText="name" 
    floatingLabelText="Your name:"/> 

該組件通過使用反應-終極版的connect函數生成的容器連接到所述存儲。現在沒有傳遞給容器的參數。並且組件中的任何地方都不會執行任何操作。

當我嘗試在我的TextField輸入一些文字,我看到被派往一些行動,從終極版-devtools我可以看到:

enter image description here

它總是被分派爲每個字符相同SET_FOCUS_PAGE行動我輸入的頁面屬性設置爲change事件TextField。另外在控制檯上我有很多的警告:

Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property `bubbles` on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See react-event-pooling for more information. 

我沒有做這一切的感覺,爲什麼是沒有訪問到該動作的部件被分派的SET_FOCUS_PAGEchange事件如何在頁面屬性中結束?那裏發生了什麼!?

回答

1

看起來您正在將合成事件傳遞給redux狀態樹。更有可能你想要而不是事件本身。

例如:

<TextField 
    hintText="name" 
    floatingLabelText="Your name:" 
    onChange={(event) => handleChangeText(event)} 
/> 

的呼叫:

const handleChangeText = (event) => { 
    console.log('the text is:', event.target.value); 
} 

如果你更新你的狀態樹,那麼你應該得到你所需要的。在哪裏我寫了console.log將是你開始採取行動來捕獲你的輸入的地方。