javascript - The data requested by the action is given to the reducer. Why is the data not mapped to the store after the reducer is executed?
黄舟
黄舟 2017-06-12 09:21:45
0
1
635
// 这是reducer
export const requestUserInfo = (state = {}, action) => {
    switch(action.type) {
        case 'HEADER_RECEIVE_USERINFO':
            console.log(action.data)// 有值
            return Object.assign({}, state, action.data)
            break
        default:
            return state
    }
}
// 这是action
function receiveUserInfo (data) {
    return {
        type: 'HEADER_RECEIVE_USERINFO',
        data
    }
}


export function requestUserInfo () {
    return dispatch => {
        return axios.post('/user/getScores', qs.stringify({
                token: token,
                uid: uid
            }))
            .then(res => {
                if(res.data.status !== 200) {
                    message.error(res.data.message)
                    return state
                }

                return { ...res.data.attachment}
            })
            .then(data => {
                dispatch(receiveUserInfo(data))
            })
    }
}

Both action and reducer can be executed normally. I monitored the store in the router, but the store has never changed. Did I write something wrong somewhere?
Someone help me, I've been stuck on this problem all day, I don't know where the problem is

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
習慣沉默

Object.assign is a shallow copy and will only process the first layer
state = {

a: name,
b: {
    child: {}    // 无论child怎么改变都不会触发state的change, 因为b的引用没有变
}

}

Is the return value of your action.data an object?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template