Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Redux action affect multiple parts of the state tree?

What is the consensus on an action affecting multiple parts of the state tree in Redux?

For example:

const ADD_POST = 'POST/ADD';

function postsReducer(state = initialState, action = {}) {
    // switch ...
    case ADD_POST:
        return {
            ...state,
            ...action.result.post
        }
}

function anotherReducer(state = initialState, action = {}) {
    // switch ...
    case ADD_POST:
        return {
            ...state,
            post_id: action.result.post.id
        }
}   

I'm seeking advice on:

Actions affecting multiple parts of the redux store/state

like image 587
AndrewMcLagan Avatar asked Apr 22 '16 07:04

AndrewMcLagan


1 Answers

Yes, absolutely. It’s the whole reason why actions exist: to separate what happened from the component’s point of view from what actually happens in terms of state change.

like image 116
Dan Abramov Avatar answered Oct 13 '22 01:10

Dan Abramov