Just a simple question for the pros. I am building a reducer and a piece of the code looks like this:
export const cusDataReducer = (state = cusDataInitialState, action) => {
let newState = {...state}
switch (action.type) {
case "CUS_READ":
newState.data = action.value;
newState.loading = false;
break;
...
The question I have is what is the difference between state
and {...state}
in this case? If I change newState=state
the code breaks. Console logs of state
and {...state}
, however, look exactly the same.
This is my store:
import {cusDataReducer} from './cusdata'
let rootReducer = combineReducers({
cusdata: cusDataReducer
});
export const Store = createStore(rootReducer,applyMiddleware(thunk))