gpt4 book ai didi

react-native - TextInput 通过引用获取值 react native

转载 作者:行者123 更新时间:2023-12-05 08:12:04 25 4
gpt4 key购买 nike

我想在功能组件中检索用户输入(我使用的是 redux 架构)。但是,当我 console.log() 一个引用项时,我得到一个构造函数,而不是实际对象。

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

  <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>

最佳答案

您无法使用 React Native 通过 ref 获取 TextInput 的值。从输入中获取文本的唯一方法是订阅更改事件。

关于react-native - TextInput 通过引用获取值 react native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39660269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com