商店没有有效的减速器-如何将组合的减速器送入商店?

时间:2020-05-09 19:32:31

标签: react-native redux react-redux

我正在努力使Redux脱颖而出,其他答案在这一点上使其更加成为障碍。

reducers / index.js

import { combineReducers } from 'redux';

import photoInputPost from './photoInputPost'
import cameraInputPost from './cameraInputPost'
import textInputPost from './textInputPost'

export default rootReducer = combineReducers({
    photoInputPost,
    textInputPost,
    cameraInputPost
})

store / index.js:

import { createStore } from 'redux'
import reducer from './../reducers/index'

export default Store = createStore(reducer)

精简工具之一 textInputPost.js

const textInputReducer = (initialState, action) => {
    console.log('textInputReducer', action);
    switch(action.type){
        case 'ADD_INPUT_TEXT':
            return { textInputValue: action.text };
    default:
        return state;
    }
}

不太确定出了什么问题,但我可能以错误的方式通过了组合减速器。

1 个答案:

答案 0 :(得分:0)

您可以按以下方式创建rootReducer文件:

import { combineReducers } from "redux";
import reducer1 from "./reducer1";
import reducer2 from "./reducer2";

const rootReducer = combineReducers({ reducer1, reducer2 });

export default rootReducer;

...并在您的index.js中,将以下rootReducer添加为:

import { createStore } from "redux";
import { Provider } from "react-redux";
import rootReducer from "./reducers/rootReducer";

import App from "./components/app";
import React from "react";
import ReactDom from "react-dom";

const store = createStore(rootReducer);

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById("root")
);