我正在尝试导航到签名屏幕,我可以预期一个字符串(用于内置组件)
错误:元素类型无效:预期一个字符串(用于内置组件)或类/函数(对于复合组件),但got:number。
检查signinscreen
的渲染方法。
import React from 'react';
import {
SafeAreaView,
View,
Text,
TextInput,
TouchableOpacity,
} from 'react-native';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import Ionicons from 'react-native-vector-icons/Ionicons';
import LoginSVG from '../assets/images/login.svg';
import GoogleSVG from '../assets/images/google.svg';
import FacebookSVG from '../assets/images/facebook.svg';
import TwitterSVG from '../assets/images/twitter.svg';
import CustomButton from '../components/CustomButton';
import InputField from '../components/InputField';
const SignInScreen = ({navigation}) => {
return (
<SafeAreaView style={{flex: 1, justifyContent: 'center'}}>
<View style={{paddingHorizontal: 25}}>
<View style={{alignItems: 'center'}}>
<LoginSVG
height={300}
width={300}
style={{transform: [{rotate: '-5deg'}]}}
/>
</View>
<Text
style={{
fontFamily: 'Roboto-Medium',
fontSize: 28,
fontWeight: '500',
color: '#333',
marginBottom: 30,
}}>
Login
</Text>
<InputField
label={'Email ID'}
icon={
<MaterialIcons
name="alternate-email"
size={20}
color="#666"
style={{marginRight: 5}}
/>
}
keyboardType="email-address"
/>
<InputField
label={'Password'}
icon={
<Ionicons
name="ios-lock-closed-outline"
size={20}
color="#666"
style={{marginRight: 5}}
/>
}
inputType="password"
fieldButtonLabel={"Forgot?"}
fieldButtonFunction={() => {}}
/>
<CustomButton label={"Login"} onPress={() => {}} />
<Text style={{textAlign: 'center', color: '#666', marginBottom: 30}}>
Or, login with ...
</Text>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 30,
}}>
<TouchableOpacity
onPress={() => {}}
style={{
borderColor: '#ddd',
borderWidth: 2,
borderRadius: 10,
paddingHorizontal: 30,
paddingVertical: 10,
}}>
<GoogleSVG height={24} width={24} />
</TouchableOpacity>
<TouchableOpacity
onPress={() => {}}
style={{
borderColor: '#ddd',
borderWidth: 2,
borderRadius: 10,
paddingHorizontal: 30,
paddingVertical: 10,
}}>
<FacebookSVG height={24} width={24} />
</TouchableOpacity>
<TouchableOpacity
onPress={() => {}}
style={{
borderColor: '#ddd',
borderWidth: 2,
borderRadius: 10,
paddingHorizontal: 30,
paddingVertical: 10,
}}>
<TwitterSVG height={24} width={24} />
</TouchableOpacity>
</View>
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
marginBottom: 30,
}}>
<Text>New to the app?</Text>
<TouchableOpacity>
<Text style={{color: '#AD40AF', fontWeight: '700'}}> Register</Text>
</TouchableOpacity>
</View>
</View>
</SafeAreaView>
);
};
export default SignInScreen;
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: number.
Check the render method of SignInScreen
.
import React from 'react';
import {
SafeAreaView,
View,
Text,
TextInput,
TouchableOpacity,
} from 'react-native';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import Ionicons from 'react-native-vector-icons/Ionicons';
import LoginSVG from '../assets/images/login.svg';
import GoogleSVG from '../assets/images/google.svg';
import FacebookSVG from '../assets/images/facebook.svg';
import TwitterSVG from '../assets/images/twitter.svg';
import CustomButton from '../components/CustomButton';
import InputField from '../components/InputField';
const SignInScreen = ({navigation}) => {
return (
<SafeAreaView style={{flex: 1, justifyContent: 'center'}}>
<View style={{paddingHorizontal: 25}}>
<View style={{alignItems: 'center'}}>
<LoginSVG
height={300}
width={300}
style={{transform: [{rotate: '-5deg'}]}}
/>
</View>
<Text
style={{
fontFamily: 'Roboto-Medium',
fontSize: 28,
fontWeight: '500',
color: '#333',
marginBottom: 30,
}}>
Login
</Text>
<InputField
label={'Email ID'}
icon={
<MaterialIcons
name="alternate-email"
size={20}
color="#666"
style={{marginRight: 5}}
/>
}
keyboardType="email-address"
/>
<InputField
label={'Password'}
icon={
<Ionicons
name="ios-lock-closed-outline"
size={20}
color="#666"
style={{marginRight: 5}}
/>
}
inputType="password"
fieldButtonLabel={"Forgot?"}
fieldButtonFunction={() => {}}
/>
<CustomButton label={"Login"} onPress={() => {}} />
<Text style={{textAlign: 'center', color: '#666', marginBottom: 30}}>
Or, login with ...
</Text>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 30,
}}>
<TouchableOpacity
onPress={() => {}}
style={{
borderColor: '#ddd',
borderWidth: 2,
borderRadius: 10,
paddingHorizontal: 30,
paddingVertical: 10,
}}>
<GoogleSVG height={24} width={24} />
</TouchableOpacity>
<TouchableOpacity
onPress={() => {}}
style={{
borderColor: '#ddd',
borderWidth: 2,
borderRadius: 10,
paddingHorizontal: 30,
paddingVertical: 10,
}}>
<FacebookSVG height={24} width={24} />
</TouchableOpacity>
<TouchableOpacity
onPress={() => {}}
style={{
borderColor: '#ddd',
borderWidth: 2,
borderRadius: 10,
paddingHorizontal: 30,
paddingVertical: 10,
}}>
<TwitterSVG height={24} width={24} />
</TouchableOpacity>
</View>
<View
style={{
flexDirection: 'row',
justifyContent: 'center',
marginBottom: 30,
}}>
<Text>New to the app?</Text>
<TouchableOpacity>
<Text style={{color: '#AD40AF', fontWeight: '700'}}> Register</Text>
</TouchableOpacity>
</View>
</View>
</SafeAreaView>
);
};
export default SignInScreen;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是由于您正在导入的SVG。如果您使用
react-native-svg
,则可能需要实现反应 - sVG转换器也是如此。请参阅这个问题有关更多信息This may be due to the SVGs that you are importing. If you're using
react-native-svg
, you may need to implement react-native-svg-transformer as well. See the top answer to this question for more info似乎当这样导入SVG文件时,它们可以作为
img
标签的图像来源提供,而不是React组件。它们需要转换为反应组件。请参阅添加svgs
create-react-app
文档。对于您的代码:
...
It seems when SVG files are imported like this, they are made available as image sources for
img
tags, not as React components. They need to be converted into React components.See Adding SVGs from the
create-react-app
docs.For your code:
...