我想检索功能组件内的用户输入(我正在使用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>
根据文档'TextInput ref = {(c)=> this._input = c}',您都需要返回该值,并可能使用此值。在构造函数中看到它。 – ajmajmajma