React native TextInput通过引用获取值react native
我想在使用redux架构的功能组件中检索用户输入。但是,当我在console.log中记录引用的项时,会得到一个构造函数,而不是实际的对象 如何在不操纵状态的情况下获取用户输入React native TextInput通过引用获取值react native,react-native,redux,React Native,Redux,我想在使用redux架构的功能组件中检索用户输入。但是,当我在console.log中记录引用的项时,会得到一个构造函数,而不是实际的对象 如何在不操纵状态的情况下获取用户输入 <Modal visible={visibleModal === 'addRoom'} onRequestClose={() => null}> <TextInput ref={el => {roomName = el}} style={styles.input} />
<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>
当您通过ref访问TextInput时,请尝试.value。当您通过ref访问TextInput时,请尝试.value。当您通过ref访问TextInput时,无法使用React Native获取TextInput by ref的值。从输入中获取文本的唯一方法是订阅更改事件。您无法通过React Native通过ref获取文本输入的值。从输入中获取文本的唯一方法是订阅更改事件。基于docs TextInput ref={c=>this.\u input=c},您都需要返回该值,并且可能需要使用该值。基于docs TextInput ref={c=>this.\u input=c},您需要返回该值,并且可能使用该值。在构造函数上查看。这可能适用于带有元素的React web,但不适用于React Native这可能适用于带有元素的React web,但不适用于React Native