2016-09-23 78 views
1

我想检索功能组件内的用户输入(我正在使用redux体系结构)。但是,当我参考项目console.log(),我得到一个构造函数,而不是实际的对象。TextInput通过引用获取值本机

如何在不操纵状态的情况下获得用户输入?

<Modal visible={visibleModal === 'addRoom'} onRequestClose={() => null}> 
    <TextInput ref={el => {roomName = el}} style={styles.input} /> 
    <Button onPress={() => store.dispatch(hideModal())}>Cancel</Button> 
    <Button onPress={() => { 
     store.dispatch(addRoom({name: roomName.value})) 
     return store.dispatch(hideModal()) 
    }}>OK</Button> 
    </Modal> 
+0

根据文档'TextInput ref = {(c)=> this._input = c}',您都需要返回该值,并可能使用此值。在构造函数中看到它。 – ajmajmajma

回答

1

访问您的TextInput您无法通过裁判得到一个TextInput的值与本地做出反应。从输入中获取文本的唯一方法是订阅更改事件。

-1

尝试.value当您通过ref

+0

这可能在React网页上使用元素,但它不适用于React Native –