gpt4 book ai didi

react-native - 在 react-native 中使用 ref 时的流程错误

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

我使用 ref能够通过 <ScrollView> 中的 from 进行制表代码有效,但我不断收到此流程错误

Cannot assign input to this.inputs.emailInput because null [1] is 
incompatible with object literal [2].

src/authentication/containers/SignIn.js
[ .2] 105│ emailInput: {},
:
199│ }}
200│ placeholder={I18n.t('email')}
201│ ref={(input) => {
202│ this.inputs.emailInput = input;
203│ }}
204│ returnKeyType={'next'}
205│ style={styles.textInput}

/private/tmp/flow/flowlib_3c65178/react.js
[1] 184│ | ((React$ElementRef<ElementType> | null) => mixed)

这里是相关代码

输入的定义:在我的 react 组件中

inputs= {
lastNameInput: {},
emailInput: {},
postalCodeInput: {},
phoneNumberInput: {},
};

一个<TextInput> render() 中的元素功能:

<TextInput
blurOnSubmit={false}
onChangeText={text => this.setState({ lastName: text })}
onSubmitEditing={() => {
this.inputs.emailInput.focus();
}}
placeholder={I18n.t('lastName')}
ref={(input) => this.inputs.lastNameInput = input}
returnKeyType={'next'}
style={styles.textInput}
underlineColorAndroid="transparent"
value={lastName}
/>

最佳答案

我认为这是因为 ref 回调可以将 null 传递给您提供的函数。我相信它会在卸载引用的组件时执行此操作。

关于react-native - 在 react-native 中使用 ref 时的流程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49883699/

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