使用react-bootstrap组件报错

新手上路,请多包涵

在使用react-boostrap的组件的时候结果报了一个错误...

Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you're trying to add a ref to a component that doesn't have an owner (that is, was not created inside of another component's `render` method). Try rendering this component inside of a new top-level component which will hold the ref.

代码大概是这个样子的:

var React = require('React');
var ReactBootstrap = require('react-bootstrap');
var DropdownButton = ReactBootstrap.DropdownButton;
var MenuItem = ReactBootstrap.MenuItem;
var ButtonToolbar = ReactBootstrap.ButtonToolbar;

var Header = React.createClass({
    render: function(){
        return (
            <ButtonToolbar>
                <DropdownButton bsStyle="link" title="default">
                    <MenuItem eventKey="1">active</MenuItem>
                    <MenuItem divider />
                </DropdownButton>
            </ButtonToolbar>
        );
    }
});

module.exports = Header;

请问是为什么呢...

阅读 6.7k
2 个回答
新手上路,请多包涵

发现问题了...var React = require('react');
改成小写的就行了......

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题