react-native - 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>
);
}
解决方案
有一个错字Apptibutton.js
,TouchableOpacity
而不是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>
);
}
推荐阅读
- python - selenium.common.exceptions.InvalidSelectorException:消息:指定了无效或非法的选择器
- google-apps-script - Google 表格自动复制、粘贴、删除
- neo4j - 如果前一个没有任何结果,Cypher Neo4J 中的 UNWIND 语句不会被执行?
- c++ - 导出编译时间常数,同时限制类可见性
- regex - 有没有办法在 Notepad++ 中自动删除符号?
- zenject - 是否可以注入一个没有与之关联的预制件/游戏对象的组件?
- python - 如何查找 A 列中的每个值的所有匹配项,该值也在 B 列中
- python - 将大型数据框加载到 Vertica
- debugging - Delve (dlv) 无法附加到进程
- c# - 使用命名的捕获组会导致不同的匹配