在使用Redux-store时,<provider store =“”>中的“store”属性提供什么?

时间:2017-08-09 06:39:58

标签: reactjs redux redux-store

根组件需要包含在内部,如

<Provider store= >
   <App />
</Provider>

但是,我不确定在store属性中提供什么。有人能让我知道吗?

1 个答案:

答案 0 :(得分:1)

我通常用它来存储这样的所有减速器。

<强> index.js

import { Provider, connect } from 'react-redux';
import ReduxThunk from 'redux-thunk';
import { createStore, applyMiddleware } from 'redux';
import reducers from './reducers';

const createStoreWithMiddleware = applyMiddleware(ReduxThunk)(createStore);
const store = createStoreWithMiddleware(reducers);

<Provider store={store}>
   {/*routers here*/}
</Provider>

<强> reducers.js

import { combineReducers } from 'redux-immutable';

// reducers import
import MainReducer from './containers/Main/reducer';
import RegisterReducer from './containers/Register/reducer';
import ChangePasswordReducer from './containers/ChangePassword/reducer';

const reducers = combineReducers({
    main: MainReducer,
    register: RegisterReducer,
    changePassword: ChangePasswordReducer
})


export default reducers;