在React native中,什么是异常违规:预期组件类得到div?

时间:2015-07-28 17:59:21

标签: react-native

我正在制作一个React Native应用程序并且出现错误Invariant Violation:期望一个组件类得到了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);

1 个答案:

答案 0 :(得分:2)

react-select是针对网络的React项目,而不是针对React Native的项目。当您尝试使用它时,React Native会发现它是使用HTML构建的,并且会抱怨<div>标记。您不能简单地使用为Web构建的组件,并希望它们适用于React Native。

相关问题