Redux in react

reducer in redux performs a minus one operation

export default (state = initialState, action) => {
  const {total} = state
  switch(action.type){
    case ActionTypes.ADD:
      // 
      return {...state, total: total + 1}
    case ActionTypes.SUBTRACT:
      // 
      return {...state, total: total - 1}
    default:
      return state
  }
}

what is the difference between return {.state, total: total-1} and return state returned by default? what is the role of
.state

Mar.31,2021

because state cannot be modified directly, .state is a copy. {.state, total: total-1} this allows you to modify only the total field in state without affecting other fields in state.

Note state.total = state.total-1; this direct assignment is not allowed by redux, so use the extension operator .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37984-2c0a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37984-2c0a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?