使用react-bootstrap组件报错

发布于 2022-09-01 07:02:03 字数 1113 浏览 17 评论 0

在使用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;

请问是为什么呢...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路黄昏 2022-09-08 07:02:03

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

寒尘 2022-09-08 07:02:03

请问你的React-bootstrap的样式这么引用的?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文