我正在从应用程序注销用户,需要从状态中清除一些用户相关数据,查找我发现Dan Abramov How to reset the state of a Redux store?字面上的这个很棒的答案 .

最后我做的是分解当前状态,然后将用户关联状态设置为undefined,如:

if (action.type === 'RESET_STORE') {
  state = {...state,
    customer: undefined,
    cart: undefined,
    course: undefined,
  }
}

仅保留州的某些部分是一个好主意吗?