简体   繁体   English

错误-元素类型无效:预期为字符串(对于内置组件)

[英]ERROR - Element type is invalid: expected a string (for built-in components)

Strange error is appearing while developing one of my React Native project. 开发我的React Native项目之一时出现奇怪的错误。 enter image description here 在此处输入图片说明

Following is the code I am using; 以下是我正在使用的代码;

    import React, {Component} from 'react';
    import {Text, View, Image, StyleSheet} from 'react-native';
    import {Content, Container} from 'native-base';
    import {Carousel} from 'react-native-looped-carousel';

    export default class AppBody extends Component {
      render() {
        return (
          <Container>
            <Content>
              <Carousel delay={500}>
                <View style={[{
                    backgroundColor: '#BADA55'
                  }
                ]}/>
                <View style={[{
                    backgroundColor: 'red'
                  }
                ]}/>
                <View style={[{
                    backgroundColor: 'blue'
                  }
                ]}/>
              </Carousel>
            </Content>
          </Container>
        );
      }
    }

    module.export = AppBody;

Your import from react-native-looped-carousel is incorrect: 您从react-native-looped-carousel import不正确:

import Carousel from 'react-native-looped-carousel'

After fixing that, the carousel won't work. 解决此问题后,轮播将无法正常工作。 Because you should provide dimensions for it: 因为您应该为其提供尺寸:

import React, { Component } from 'react'
import { Text, View, Image, StyleSheet, Dimensions } from 'react-native'
import { Content, Container } from 'native-base'
import Carousel from 'react-native-looped-carousel'

const {width, height} = Dimensions.get('window')
export default class AppBody extends Component {

  constructor(props) {
    super(props)

    this.state = {
      size: {width, height},
    }
  }

  render() {
    return (
      <Container>
        <Content>
          <Carousel
            delay={2000}
            style={this.state.size}
            autoplay
            pageInfo
            onAnimateNextPage={(p) => console.log(p)}
          >
            <View style={[{backgroundColor: '#BADA55'}, this.state.size]}><Text>1</Text></View>
            <View style={[{backgroundColor: 'red'}, this.state.size]}><Text>2</Text></View>
            <View style={[{backgroundColor: 'blue'}, this.state.size]}><Text>3</Text></View>
          </Carousel>
        </Content>
      </Container>
    )
  }
}

module.export = AppBody

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mdbreact 错误 - 元素类型无效:需要一个字符串(对于内置组件) - mdbreact error - Element type is invalid: expected a string (for built-in components) 错误:元素类型无效:需要一个字符串(对于内置组件)-reactjs - Error: Element type is invalid: expected a string (for built-in components) - reactjs 错误 - 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - error - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined TypeScript + React:元素类型无效:预期为字符串(对于内置组件) - TypeScript + React: Element type is invalid: expected a string (for built-in components) redux 表单元素类型无效:应为字符串(对于内置组件) - redux form Element type is invalid: expected a string (for built-in components) React Native,元素类型无效:需要一个字符串(对于内置组件) - React Native, element type is invalid: expected a string (for built-in components) 错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:ReactJS 中的对象 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object in ReactJS 错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:对象 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 渲染错误元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Render Error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM