目前,我正在使用此设置(为便于阅读而简化):
react_on_rails 11.1.4
布局控制器(索引方法):
redux_store('appStore', props: { foo: 'bar' })
布局:
<%= redux_store_hydration_data %> (before close of body tag)
看法:
<%= react_component('FooBar') %>
组件(FooBar):
ReactOnRails.getStore('appStore');
JavaScript (main.js):
ReactOnRails.registerStore({ appStore });
如果我检查源,数据和组件似乎存在:
<div id="FooBar-react-component-fb8d03cb-b3d3-4247-8b4b-3e5a2ad52f84"></div>
<script type="application/json" class="js-react-on-rails-component" data-component-name="FooBar" data-trace="true" data-dom-id="FooBar-react-component-fb8d03cb-b3d3-4247-8b4b-3e5a2ad52f84">{}</script>
<script src="/main.js"></script>
<script type="application/json" data-js-react-on-rails-store="appStore">{"foo":"bar"}</script>
但是,由于这些致命错误,组件本身不会呈现:
Uncaught Error: There are no stores hydrated and you are requesting the store appStore...`
Uncaught Error: Could not find store registered with name 'appStore'. Registered store names include...
据我所知,设置与文档中概述的内容一致,所以我想知道这是否是某种错误。我尝试将调用放在redux_store
控制器和视图中,将其他调用移动到其他文件和位置等,但无济于事。
非常感谢任何帮助,在此先感谢!