我正在使用
打字稿
使用react native,我不知道是否定义了正确的输入引用类型。
下面是我的代码的相关部分:(这两个组件都是我的自定义组件,
TextInput
不适用于React Native。)
// in begin of class
private readonly passwordInputRef: React.RefObject<Password> = createRef();
// in render function
<TextInput
key={'login page username'}
language={language}
placeholder={'Username:'}
value={username}
containerStyle={styles.username}
hasError={loginError}
onChangeText={this.setUsername}
returnKeyType={"next"}
blurOnSubmit={false}
onSubmitEditing={() => this.passwordInputRef.current!.focus()} />
<Password
key={'login page password'}
ref={this.passwordInputRef}
language={language}
placeholder={'Password:'}
value={password}
containerStyle={styles.password}
hasError={loginError}
onChangeText={this.setPassword}/>
当我运行应用程序并按下键盘上的“下一步”按钮时,它会给我一个错误。
_this.passwordInputRef.current.focus is not a function
我在StackOverflow上搜索并阅读了许多答案,但没有一个答案能解释它是如何与typescript一起工作的。
我也读过这个
issue on github
,似乎我的代码与此非常相似,但我使用的是typescript,所以我认为我的define命令有问题
passwordInputRef
.
我做错了什么?
目前我正在使用:
"react": "16.5.2"
"react-native": "0.55.2"