gpt4 book ai didi

javascript - 不变违规 : Element type is invalid on login page react-native

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:57 25 4
gpt4 key购买 nike

所以我是 reactnative 的新手,目前我正在用 react native 制作一个登录页面,我得到了这个 error在我的应用程序上

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of 'Button'.

这里是 App.js

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as firebase from 'firebase';
import { Input } from './components/Input';
import { Button } from './components/Button';

export default class App extends React.Component {
state = {
email: '',
password: ''
}
render() {
return (
<View style={styles.container}>
<Input
placeholder='Enter your mail...'
label='Email'
onChangeText={email => this.setState({email})}
value={this.state.email}
/>
<Input
placeholder='Enter your password'
label='Password'
secureTextEntry
onChangeText={password => this.setState({password})}
value={this.state.password}
/>
<Button onPress={() => console.log('pressed')}>Log In</Button>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20
},
});

这是 Button.js

import React from 'react';
import {StyleSheet, Text, TouchableOpactity} from 'react-native';

const Button = ({ onPress, children }) => {
return (
<TouchableOpactity onPress={onPress} style={styles.button}>
<Text style={styles.text}> { children } </Text>
</TouchableOpactity>

)
}

const styles = StyleSheet.create({
button: {
marginTop: 10,
padding: 20,
width: '100%',
backgroundColor: '#00aeef',
borderRadius: 4,
alignItems: 'center',
},
text: {
color: 'white',
fontWeight: '700',
fontSize: 18,
}
});

export { Button };

知道为什么我的应用会发生这种情况吗?谢谢

更新:我按照下面的解决方案,它提出了另一个 error

任何解决方案

最佳答案

在你的 Button.js 中你应该写:

export default Button;

你的导入应该是:

import Button from './components/Button';

代替:

export { Button };

在这种情况下,最好使用 export default Button

关于javascript - 不变违规 : Element type is invalid on login page react-native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51377017/

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