提问者:小点点

错误:要求还原程序为函数-MERN应用程序


我正在开发一个MERN应用程序,代码部署在Heroku上,运行良好。 但是,由于我在store.js中为生产构建添加了三元运算符,它在开发中就不再工作了。

store.js

import { createStore, applyMiddleware, compose } from "redux"
import thunk from "redux-thunk"
import rootReducer from "./reducers/Layout"

const initialState = {}

const middleware = [thunk]

const store = createStore(
    rootReducer, 
    initialState, 
    compose(
        applyMiddleware(...middleware),
        (
            (process.env.NODE_ENV === 'production') ? 
             compose : 
            (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose)
        )
    )
)

export default store

我从layout.js(index.js替换)导入了rootReducer,但它在添加三元运算符之前工作得很好。 但以防万一,这里是我的layout.js中的combineReducers函数。

layout.js(index.js替换)

import { combineReducers } from "redux"
import RuleReducer from "./RuleReducer"
import ErrorReducer from "./ErrorReducer"
import AuthReducer from "./AuthReducer"

export default combineReducers({
    rule: RuleReducer,
    error: ErrorReducer,
    auth: AuthReducer
})

共1个答案

匿名用户

好吧,所以我不是瞎了就是傻了,但是感谢Andreas,他对我的问题发表了评论,我只是修改了我的三元运算符,对于任何经历过同样问题的人来说,这里是修改:

import { createStore, applyMiddleware, compose } from "redux"
import thunk from "redux-thunk"
import rootReducer from "./reducers/Layout"

const initialState = {}

const middleware = [thunk]

const stage = (process.env.NODE_ENV === 'production') ? compose : (window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())

const store = createStore(
    rootReducer, 
    initialState, 
    compose(
        applyMiddleware(...middleware),
        stage
    )
)

export default store