You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
最近把一些在项目中用到的组件抽离出来,封装成一个组件库,然后关联出去npm link,再在原项目中通过npm link my-components的方式关联回这个组件库。
运行时发现一个错误:
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 (details: fb.me/react-refs-must-have-owner).
检查过后并没用发现在render函数以外的地方用到ref,于是怀疑是不是have multiple copies of React loaded。
最近把一些在项目中用到的组件抽离出来,封装成一个组件库,然后关联出去
npm link
,再在原项目中通过npm link my-components
的方式关联回这个组件库。运行时发现一个错误:
检查过后并没用发现在
render
函数以外的地方用到ref
,于是怀疑是不是have multiple copies of React loaded
。在这里找到两种解决方案:
npm-link
的方式:这两种方法都达到使react都指向同一份引用,后者更适用于库的开发。
The text was updated successfully, but these errors were encountered: