首页 > 解决方案 > Invariant Violation:元素类型无效 React-Native

问题描述

当我尝试在我的代码中创建可重用组件时,它显示了一些错误。

在此处输入图像描述

以下是我的代码

登录.js

render() {
  return (
    <View style={login.container}>
      <Image source={imageLogo} style={login.logo} />
      <View style={login.form}>
        <ApptiTextInput
          value={this.state.email}
          onChangeText={this.handleEmailChange}
          placeholder={strings.EMAIL_PLACEHOLDER}
        />
        <ApptiTextInput
          value={this.state.password}
          onChangeText={this.handlePasswordChange}
          placeholder={strings.PASSWORD_PLACEHOLDER}
        />
        <ApptiButton label={strings.LOGIN} handleLoginPress={this.handleLoginPress.bind(this)} />
      </View>
    </View>
  );
}

Apptibutton.js

render() {
    const { label, handleLoginPress } = this.props;
    console.log(label);

    return (
      <View  style={apptiButton.container}>
         <TouchableOptacity onPress={handleLoginPress}>
            <Text style={apptiButton.text} >{label}</Text>
         </TouchableOptacity>
      </View>

    );
}

这是我的代码

标签: react-native

解决方案


有一个错字Apptibutton.jsTouchableOpacity而不是TouchableOptacity

render() {
    const { label, handleLoginPress } = this.props;
    console.log(label);

    return (
      <View  style={apptiButton.container}>
         <TouchableOpacity onPress={handleLoginPress}>
            <Text style={apptiButton.text} >{label}</Text>
         </TouchableOpacity>
      </View>

    );
}

推荐阅读