Importing a react component from a Rails engine into an application

不羁岁月 提交于 2019-12-10 23:11:58

问题


I am using react_on_rails for developing a Rails Engine and an application.

I have written a rails engine which has a single component - NewComponent. It uses react_on_rails. This has been tested via the dummy application of the rails engine. I imported and registered the component in dummy application: /new_engine/test/dummy/client/app/Index.jsx:

import NewComponent from '../../../../client/app/pages/user_home_page/NewComponent';

ReactOnRails.register({
NewComponent,
});

The above worked completely fine in the dummy app. And I was able to further render this registered component in the view.

Now I am consuming this react component as a mountable rails engine in a full fledged application. How can I import this component so that I can register it in the application? In the dummy application I was able to give a relative path to import the component. Such a relative path will not be possible in the application while consuming the gem.

I have checked online for an answer to this, but there seems to be very less documentation on react_on_rails with engines.

来源:https://stackoverflow.com/questions/46696659/importing-a-react-component-from-a-rails-engine-into-an-application

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