Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Redux combineReducers()不是';不承认国家_Reactjs_Redux_Reducers_Redux Reducers - Fatal编程技术网

Reactjs Redux combineReducers()不是';不承认国家

Reactjs Redux combineReducers()不是';不承认国家,reactjs,redux,reducers,redux-reducers,Reactjs,Redux,Reducers,Redux Reducers,我正在使用redux combinereducer()组合2个减速机。虽然它们都在开发工具中被识别,但其中一个只是一个空对象,即使我将一个具有不同属性的对象传递到了reducer中 combineReducers()文件: 第一个减速器: import { SINGLE_JOB_POST_SUCCESS } from './constants' const initial = { jobs: [], job: {} } export default (state = init

我正在使用redux combinereducer()组合2个减速机。虽然它们都在开发工具中被识别,但其中一个只是一个空对象,即使我将一个具有不同属性的对象传递到了reducer中

combineReducers()文件:

第一个减速器:

import { SINGLE_JOB_POST_SUCCESS } from './constants'

const initial = {
    jobs: [],
    job: {}
}

export default (state = initial, action) => {
    const { type, payload } = action
    switch (type) {
        case SINGLE_JOB_POST_SUCCESS:
            return {
                ...state,
                jobs: [
                    ...state.jobs,
                    ...payload
                ]
            }
        default:
            return {}
    }
}
第二个减速器:

import { RESET_AUTH_RESPONSE } from './constants'

const initial = {
    authResponse: null,
    user: {}
}

export default (state = initial, action) => {
    const { type, payload } = action
    switch (type) {
        case RESET_AUTH_RESPONSE:
            return {
                ...state,
                authResponse: null
            }
        default:
            return state
    }
}

在redux开发工具中查看状态时,“auth”具有相关属性,但“job”只是一个空对象。我用不同的名称调用了reducer文件,以消除对别名的需要,但没有效果。非常感谢您的帮助。

因为您的
authReducer
具有:

默认值:
返回{}
因此,每当它看到一个它无法识别的动作时,它都会返回一个空对象。您需要将其改为
返回状态

另外,请注意,您应该切换到使用,这将大大简化Redux逻辑

import { RESET_AUTH_RESPONSE } from './constants'

const initial = {
    authResponse: null,
    user: {}
}

export default (state = initial, action) => {
    const { type, payload } = action
    switch (type) {
        case RESET_AUTH_RESPONSE:
            return {
                ...state,
                authResponse: null
            }
        default:
            return state
    }
}