简体   繁体   English

在React Native中获取“未定义不是对象(评估StyleSheet.create)”错误

[英]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.

相关问题 React Native错误:undefined不是对象(评估&#39;Object.keys(dataBlob [sectionID])&#39;) - React Native error: undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])') React native Undefined不是对象(评估&#39;_react3.default.PropType.shape&#39;) - React native Undefined is not an object(evaluating'_react3.default.PropType.shape') 错误未定义不是对象(评估&#39;this.props.navigation.navigate&#39;)// React-native - Error undefined is not an object (evaluating 'this.props.navigation.navigate') // React-native React-Native Navigator“未定义不是对象(正在评估this.props.navigator)”错误 - React-Native Navigator “Undefined is not an object (evaluating this.props.navigator)” error React Native - 错误:未定义不是对象(评估&#39;require(&#39;NativeModules&#39;)。UIManager.AndroidDrawerLayout.Constants&#39;) - React Native - Error: undefined is not an object (evaluating 'require('NativeModules').UIManager.AndroidDrawerLayout.Constants') 反应本机。 未定义不是对象(评估“ this.props.navigator.push”) - React native. undefined is not object (evaluating 'this.props.navigator.push') React Native Fetch Blob - undefined不是对象(评估'RNFetchBlob.DocumentDir') - React Native Fetch Blob - undefined is not an object (evaluating 'RNFetchBlob.DocumentDir') React-Native-未定义不是对象(“评估this._component.getScrollableNode”) - React-Native - undefined is not an object (“evaluating this._component.getScrollableNode”) React Native:另一个“未定义不是对象(评估action.type) - React Native: Yet another "Undefined is not an object (evaluating action.type) TypeError: Undefined is not an object (评估 '_pushNotifications.pushNotifications.configure') React Native - TypeError: Undefined is not an object (evaluating '_pushNotifications.pushNotifications.configure') React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM