我正在使用react-rails和browserify。在我的application.js使用如何避免reactjs在rails和reactjs环境中被包含两次?
// require react
// require react-ujs
而且我用
var t=require("tcomb-form")
当我看到reactjs包括在我的资产管道事半功倍的效果使用tcomb形式。
我应该如何正确使用reactjs与rails?
编辑:
顺便说一下,如果你在你的控制台看到此错误,可能是你有得到了包括两次reactjs同样的问题。
[Error] Error: 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.
我会尝试,所以你的方式react_ujs不抱怨无法找到React? – ziweizhou
抱歉,它不起作用,除非您将React声明为全局变量。否则react_ujs会抱怨找不到React。 未捕获ReferenceError:未定义反应 – ziweizhou
是的。我输错了它,应该已经在全球范围内了。固定在上面。另一种我一直试图让服务器端渲染工作的方式是预编译/ browserify,并要求上面的react_ujs包。仍在继续努力并开展摩卡测试。 –