我正在使用onChangeText事件和状态获取TextInput的文本。
<View style={styles.inputContainerStyle}>
<TextInput
autoFoucs={true}
ref={inputRef}
style={styles.textInputStyle}
placeholder="type here ..."
placeholderTextColor='#838389'
multiline
underlineColorAndroid="transparent"
onChangeText={text => handleTextChange(text)}
value={selectedText}
/>
<TouchableOpacity style={styles.submitBtnWrapperStyle} onPress={() => handleMsgSend()}>
<Icon name={msgEditMode ? "check" : "paper-plane"} size={20} color="#ffffff" />
</TouchableOpacity>
</View>
...
// handle text change on textinput
const handleTextChange = text => {
channel && channel.typing();
setSelectedText(text);
}
但是实际上,每当更改文本时,由于状态值的更改也会调用render函数,这会使整个屏幕变慢。
所以我正在寻找不使用onChangeText
事件来获取文本的替代方法。
有没有使用ref来获取文本的本地方法?
希望我能提供帮助。
谢谢...
是,您可以使用ref这样访问文本输入的值