React Native:无法使用 ref 在 returnKeyType="next" 上切换到下一个 TextInput

Posted

技术标签:

【中文标题】React Native:无法使用 ref 在 returnKeyType="next" 上切换到下一个 TextInput【英文标题】:React Native : Not able to switch to next TextInput on returnKeyType="next" using ref 【发布时间】:2022-01-16 16:16:09 【问题描述】:

我正在尝试将焦点从一个 TextInput 移动到键盘上的另一个上,然后按下打字稿中的以下代码

但它显示“类型'never'.ts(2339) 上不存在属性'focus'”错误

有没有其他方法可以做同样的功能

const emailRef = React.useRef()
const passwordRef = React.useRef()

<TextInput
     ref=emailRef                              // Current TextInput Ref
     onSubmitEditing=()=>passwordRef .current?.focus()  // Changing focus
     secureTextEntry=isSecured
     placeholder=placeHolder
     placeholderTextColor=GREY[400]
     selectionColor=GREY[900]
     style=styles.inputText
     onChangeText=onChangeText
     keyboardType=keyboardType
     onEndEditing=onEndEditing
     autoFocus=autoFocus
     returnKeyType=returnKeyType
/>

【问题讨论】:

重复***.com/questions/53390679/… 【参考方案1】:

你可以试试这个

inputRef = React.createRef<TextInput>();

【讨论】:

工作正常?

以上是关于React Native:无法使用 ref 在 returnKeyType="next" 上切换到下一个 TextInput的主要内容,如果未能解决你的问题,请参考以下文章