export function reducer(state, action) { switch (action.type) { case "onCredentialsChange": { const { prop, value } = action.payload; return { ...state, credentials: { ...state.credentials, [prop]: value } }; } case "onNetworkChange": { const { prop, value } = action.payload; return { ...state, network: { ...state.network, [prop]: value } }; } case "onAuthorizationTokenChange": { const { token } = action.payload; return { ...state, security: { ...state.security, authorization: { ...state.security.authorization, token } } }; } default: { return state; } } } export const dispatchActions = dispatch => ({ onCredentialsChange: (prop, value) => dispatch({ type: "onCredentialsChange", payload: { prop, value } }), onNetworkChange: (prop, value) => dispatch({ type: "onNetworkChange", payload: { prop, value } }), onAuthorizationTokenChange: token => dispatch({ type: "onAuthorizationTokenChange", payload: { token } }) });