L
L
laguna11322018-07-23 13:05:54
React
laguna1132, 2018-07-23 13:05:54

The specifics of the work of the reducer?

Hey! Let's say we have a reducer:

export const reducer = (state = initialState, action) => {
    const result = Object.assign({}, state);
    switch (action.type) {
        case 'TEST_ACTION':
            return result;
        default:
            return result;
    };
};

Logically, with the help of Object.assign() we create a new object, and even if we do not change it, redux must re-render the signed components. But that doesn't happen. Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-07-23
@laguna1132

I sketched an example, I did not take out the action separately, I think this will not confuse.
Re-rendering will happen - https://codesandbox.io/s/m43v2pmxj9
(clicking on the button causes console.log 'render')
ps therefore, if it doesn't work for you, then either there was a mistake in the subscription (in mapStateToProps), or somewhere else. Do the same example on codesandbox, we'll figure it out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question