【问题标题】:Flow error when using ref in react-native在 react-native 中使用 ref 时出现流量错误
【发布时间】:2019-01-01 01:49:45
【问题描述】:

我使用ref 能够通过<ScrollView> 中的一个标签 该代码有效,但我不断收到此流程错误

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)

这里是相关代码

输入定义: 在我的反应组件中

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

render() 函数中的 &lt;TextInput&gt; 元素:

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

【问题讨论】:

    标签: react-native flowtype


    【解决方案1】:

    我认为这是因为 ref 回调可以将 null 传递给您提供的函数。我相信当引用的组件被卸载时它会这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 2020-04-23
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      相关资源
      最近更新 更多