ReactDnD: “Invariant Violation: addComponentAsRefTo” Error

大城市里の小女人 提交于 2019-12-24 15:49:39

问题


Dear people of StackOverflow,

I am trying to implement Drag and Drop functionality in a React-Rails app. However, as soon as I add the DragDropContext to the top level component, I see this error in the browser console:

'react.self-0f0e88a….js?body=1:1087 Uncaught Error: 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'

This is the only code I currently have for the app:

var App = React.createClass({
    render: function() {
        return (
            <div>
                Hello
            </div>
        );
    }
});

Components.App = DnD.DragDropContext(HTML5Backend)(App);

Adding this one line of code is causing all of our PhantomJS integration tests to fail. Any help would be appreciated. Thanks!

Edit: As requested, here is our index.html.erb where we render App.

<%= react_component 'Components.App' %>

回答1:


After a little digging into the react version, we discovered that we actually had two versions of react being used at the same time. One was hidden inside react-rails, while the other was from our node-modules. We removed the 'require "react"' statement from our sprockets file, and everything seems to work now.



来源:https://stackoverflow.com/questions/37579528/reactdnd-invariant-violation-addcomponentasrefto-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!