【问题标题】:Can I have my apps share single redux store?我可以让我的应用程序共享单个 redux 商店吗?
【发布时间】:2017-04-10 18:25:18
【问题描述】:

我有一个复杂的分析 html 页面,我已经将大部分元素转换为 react 组件,我的大部分元素被组织成顶部/底部两个部分。

我的设置正在运行,但是,我想知道这是否是合法/正确的设置方式?

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';

import TopSection from './components/app';
import BottomSection from './components/app_content';
import reducers from './reducers';

const createStoreWithMiddleware = applyMiddleware()(createStore);

// Top Section 

ReactDOM.render(
  <Provider store={createStoreWithMiddleware(reducers)}>
    <TopSection />
  </Provider>
  , document.querySelector('.top-section'));

// Bottom Section 

ReactDOM.render(
  <Provider store={createStoreWithMiddleware(reducers)}>
    <BottomSection />
  </Provider>
  , document.querySelector('.bottom-section'));

【问题讨论】:

  • 你的意思是你想让他们使用一个商店?从这里开始,您将创建两个仅共享减速器的商店。

标签: redux react-redux


【解决方案1】:

如果确实需要,您可以拥有多个商店。但强烈建议不要使用多个商店设置。单店总是最好的选择,因为,

  • 很可靠
  • 很快
  • 调试很简单

这里是链接,为什么不建议设置多个商店。

redux.js.org

stackoverflow.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2012-04-14
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多