You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the addition of the [callback syntax for createSlice](#callback-syntax-for-createslicereducers), the [suggestion](https://github.com/reduxjs/redux-toolkit/issues/3837) was made to enable custom slice reducer creators. These creators would be able to:
712
+
713
+
- Modify reducer behaviour by adding case or matcher reducers
714
+
- Attach actions (or any other useful functions) to `slice.actions`
715
+
- Attach provided case reducers to `slice.caseReducers`
716
+
717
+
The creator would need to first return a "definition" shape when `createSlice` is first called, which it then handles by adding any necessary reducers and/or actions.
718
+
719
+
An API for this is not set in stone, but the existing `create.asyncThunk` creator implemented with a potential API could look like:
720
+
721
+
```js
722
+
constasyncThunkCreator= {
723
+
type:ReducerType.asyncThunk,
724
+
define(payloadCreator, config) {
725
+
return {
726
+
type:ReducerType.asyncThunk, // needs to match reducer type, so correct handler can be called
727
+
payloadCreator,
728
+
...config,
729
+
}
730
+
},
731
+
handle(
732
+
{
733
+
// the key the reducer was defined under
734
+
reducerName,
735
+
// the autogenerated action type, i.e. `${slice.name}/${reducerName}`
if (pending) context.addCase(asyncThunk.pending, pending)
748
+
if (fulfilled) context.addCase(asyncThunk.fulfilled, fulfilled)
749
+
if (rejected) context.addCase(asyncThunk.rejected, rejected)
750
+
if (settled) context.addMatcher(asyncThunk.settled, settled)
751
+
752
+
context.exposeAction(reducerName, asyncThunk)
753
+
context.exposeCaseReducer(reducerName, {
754
+
pending: pending || noop,
755
+
fulfilled: fulfilled || noop,
756
+
rejected: rejected || noop,
757
+
settled: settled || noop,
758
+
})
759
+
},
760
+
}
761
+
762
+
constcreateSlice=buildCreateSlice({
763
+
creators: {
764
+
asyncThunk: asyncThunkCreator,
765
+
},
766
+
})
767
+
768
+
consttodoSlice=createSlice({
769
+
name:'todos',
770
+
})
771
+
```
772
+
773
+
We're not sure how many people/libraries would actually make use of this though, so any feedback over on the [Github issue](https://github.com/reduxjs/redux-toolkit/issues/3837) is welcome!
774
+
775
+
### `createSlice.selector` selector factories
776
+
777
+
There have been some concerns raised internally about whether `createSlice.selectors` supports memoized selectors sufficiently. You can provide a memoized selector to your `createSlice.selectors` configuration, but you're stuck with that one instance.
With `reselect`'s default cache size of 1, this can cause caching issues if called in multiple components with different arguments. One typical solution for this (without `createSlice`) is a [selector factory](https://redux.js.org/usage/deriving-data-selectors#creating-unique-selector-instances):
const todos =useSelector((state) =>selectTodosByAuthor(state, author))
811
+
}
812
+
```
813
+
814
+
Of course, with `createSlice.selectors` this is no longer possible, as you need the selector instance when creating your slice.
815
+
816
+
In 2.0.0 we have no set solution for this - a few APIs have been floated ([PR 1](https://github.com/reduxjs/redux-toolkit/pull/3671), [PR 2](https://github.com/reduxjs/redux-toolkit/pull/3836)) but nothing was decided upon. If this is something you'd like to see supported, consider providing feedback in the [Github discussion](https://github.com/reduxjs/redux-toolkit/discussions/3387)!
712
817
713
818
### 3.0 - RTK Query
714
819
820
+
RTK 2.0 was largely focused on core and toolkit changes. Now that 2.0 is released, we would like to shift our focus to RTK Query, as there is still some rough edges to iron out - some of which may require breaking changes, necessitating a 3.0 release.
821
+
822
+
If you have any feedback for what that could look like, please consider chiming in at the [RTK Query API pain points and rough spots feedback thread](https://github.com/reduxjs/redux-toolkit/issues/3692)!
0 commit comments