在使用 createSlice() over createReducer() 时是否有任何特定用法 advantage/disadvantage 除了样板缩减

Is there any specific usage advantage/disadvantage in using createSlice() over createReducer() other than the boilerplate reduction

我提到了几个链接,包括 https://github.com/reduxjs/redux-toolkit/issues/81。但它早在 2019 年就得到了回答,但并不是很有帮助。

由于 createSlice 在内部使用 createReducer,简短的回答是否定的,主要优点是样板。

请记住,在 createReducercreateSliceextraReducers 中,我们建议您使用构建器符号而不是对象映射符号,因为后者是不可能的稍后只需移植到 TypeScript,并且像匹配器这样的高级东西通过构建器表示法更容易使用。

此外,我想不出使用 createReducer 而不是 createSlice 的单一理由,只要你生成的 reducer 至少有一个应该与 reducer 一起创建的单一动作类型.