简体   繁体   English

未捕获的不变违反:addComponentAsRefTo(…):只有ReactOwner可以具有引用

[英]Uncaught Invariant Violation: addComponentAsRefTo(…): Only a ReactOwner can have refs

I am trying to use react-data-grid ( http://adazzle.github.io/react-data-grid/index.html ) but I keep getting the error: 我正在尝试使用react-data-grid( http://adazzle.github.io/react-data-grid/index.html ),但我不断收到错误消息:

invariant.js:17 Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded.

I have tried uninstalling the package and reinstalling to no avail. 我尝试卸载软件包并重新安装无济于事。

Here is my code: 这是我的代码:

render() {
    ...
    var _rows = [];
        for (var i = 1; i < 1000; i++) {
            _rows.push({
                id: i,
                title: 'Title ' + i,
                count: i * 1000
            });
        }

        var rowGetter = function(i){
            return _rows[i];
        };

        const columns = [
            {
                key: 'id',
                name: 'ID'
            },
            {
                key: 'title',
                name: 'Title'
            },
            {
                key: 'count',
                name: 'Count'
            }
        ]
   return (
        ...
<ReactDataGrid
                                columns={columns}
                                rowGetter={rowGetter}
                                rowsCount={_rows.length}
                                minHeight={277} />
...
   )
}

How can I fix this? 我怎样才能解决这个问题?


I altered my config.js: 我更改了config.js:

...
"npm:react-data-grid@0.14.42": {
      "classnames": "npm:classnames@1.2.2",
      "es5-shim": "npm:es5-shim@4.5.8",
      "fbjs": "npm:fbjs@0.6.1",
      "object-assign": "npm:object-assign@2.1.1",
      "process": "github:jspm/nodelibs-process@0.1.2",
      //"react": "npm:react@0.14.8",
      "react-contextmenu": "npm:react-contextmenu@1.5.0",
      //"react-dom": "npm:react-dom@0.14.8",
      "ron-react-autocomplete": "npm:ron-react-autocomplete@3.0.1"
    },
...

And now it works. 现在就可以了。

or you have multiple copies of React loaded. 或者您已经加载了多个React副本。

Every time I got this error it was because I had react loaded twice, make sure you only load React once, especially if you're using webpack 每次收到此错误是因为我已将React加载两次,请确保仅加载React一次,尤其是如果您使用的是webpack

暂无
暂无

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

相关问题 测试:`错误:永久违反:addComponentAsRefTo(...):只有ReactOwner可以具有引用。`错误 - Testing: `Error: Invariant Violation: addComponentAsRefTo(…): Only a ReactOwner can have refs.` error addComponentAsRefTo(…):只有ReactOwner可以拥有refs-选择列表形式的错误 - addComponentAsRefTo(…): Only a ReactOwner can have refs - Error in Form with Select List 只有ReactOwner可以具有引用 - Only a ReactOwner can have refs React组件可以在浏览器中正确渲染,但是Jest在渲染时会测试错误:“只有ReactOwner可以具有引用” - React components render correctly in browser, but Jest test errors when rendering: “Only a ReactOwner can have refs” React ref无法正常运行:违反了addComponentAsRefTo - React ref not working Invariant Violation: addComponentAsRefTo 只有ReactOwner可以有refs。 您可能正在向组件的render方法中未创建的组件添加ref - Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method 反应:裁判抛出错误-&#39;未捕获的错误:不变违反&#39; - React: refs throwing an error - 'Uncaught Error: Invariant Violation' 错误:不变违反:使用react-router时addComponentAsRefTo - Error: Invariant Violation: addComponentAsRefTo when using react-router 反应-未捕获的不变违规: - React - Uncaught Invariant Violation: 反应警报未捕获的不变违规 - React alert Uncaught Invariant Violation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM