在 React Native 中,Invariant Violation: expected a component class got div 的异常是什么? [英] In React native, what is the exception Invariant Violation: expected a component class got div?

查看:38
本文介绍了在 React Native 中,Invariant Violation: expected a component class got div 的异常是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个 React Native 应用程序并收到错误 Invariant Violation: expected a component class got div

I'm making a React Native app and got the error Invariant Violation: expected a component class got div

这是什么意思?

这是应用程序:

'use strict';

var React = require('react-native');
var {
  Text,
  View,
  AppRegistry
} = React;

var Select = require('react-select');

var options = [
  { value: 'val1', label: 'Value 1' },
  { value: 'val2', label: 'Value 2' },
];


var MyApp = React.createClass({
  render: function() {
    return (
      <View>
        <Text>I am selecting:</Text>
        <Select
            name="form-field-name"
            value="val1"
            options={options}
        />
      </View>
    );
  }
});

AppRegistry.registerComponent('AwesomeProject', () => MyApp);

推荐答案

react-select 是 React for web 的项目,而不是 React Native 的项目.当你尝试使用它时,React Native 发现它是使用 HTML 构建的,并抱怨 <div> 标签.您不能简单地使用为 Web 构建的组件并期望它们适用于 React Native.

react-select is a project for React for the web, not for React Native. When you try to use it, React Native sees that it is built using HTML and complains about the <div> tag. You can't simply use components built for the web and expect them to work for React Native.

这篇关于在 React Native 中,Invariant Violation: expected a component class got div 的异常是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆