Reducer are pure fucntions which take the previous state of the app and return a new state based on the action passed to it.
const language = (state, action) => {
let newState = {...state};
if (action.type == "SET_LANGUAGE") {
newState.lang_code = action.lang_code;
}
return newState;
}
Always remember that we should never mutate state inside the reducer, always return a new copy of state.
You can achieve this using
Object.assign()
Spread (…) operator