[英]Getting “Undefined is not an object (evaluating StyleSheet.create)” error in React Native
I'm new to react-native and i'm trying to use swipe navigation in an app I'm creating. 我是新手反应原生,我正在尝试在我正在创建的应用中使用滑动导航。 I've installed randomcolor, as well as native-react-swipe but for some reason I'm still getting an error.
我已经安装了randomcolor,以及native-react-swipe,但由于某种原因,我仍然遇到错误。
import React, {Component} from 'react';
import Swiper from 'react-native-swiper'
import randomcolor from 'randomcolor'
const {
View,
Text,
StyleSheet
} = React
const styles = StyleSheet.create({
container: {
flex: 1
},
view: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
});
class TitleText extends React.Component {
render() {
return (
<Text style={{ fontSize: 48, color: 'white' }}>
{this.props.label}
</Text>
)
}
}
class Home extends React.Component {
viewStyle() {
return {
flex: 1,
backgroundColor: randomcolor(),
justifyContent: 'center',
alignItems: 'center',
}
}
render() {
return (
<Swiper
loop={false}
showsPagination={false}
index={1}>
<View style={this.viewStyle()}>
<TitleText label="Left" />
</View>
<Swiper
horizontal={false}
loop={false}
showsPagination={false}
index={1}>
<View style={this.viewStyle()}>
<TitleText label="Top" />
</View>
<View style={this.viewStyle()}>
<TitleText label="Home" />
</View>
<View style={this.viewStyle()}>
<TitleText label="Bottom" />
</View>
</Swiper>
<View style={this.viewStyle()}>
<TitleText label="Right" />
</View>
</Swiper>
)
}
}
export default Home
The error I'm getting says "undefined is not an object (evaluating 'StyleSheet.create')". 我得到的错误说“undefined不是一个对象(评估'StyleSheet.create')”。 I've been trying to crack it for a while now, but haven't had any luck.. That's the code that I have, any help would be greatly appreciated!
我一直试图破解它一段时间,但没有运气..这是我的代码,任何帮助将不胜感激!
In order to access React Native components
you need to import them from react-native
and not react
要访问React Native
components
您需要从react-native
导入它们而不进行react
import {
View,
Text,
StyleSheet
} from 'react-native'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.