apiweiser/reduxjs_toolkit-1-to-2
Redux Toolkit 1 to 2: object notation of createSlice.extraReducers and createReducer to the builder callback
# reduxjs_toolkit-1-to-2
Redux Toolkit 2 removes the object notation of `createSlice`'s `extraReducers`
and of `createReducer` ([migration guide](https://redux-toolkit.js.org/usage/migrating-rtk-2)).
This codemod rewrites both to the builder callback:
```js
extraReducers: {
[fetchPosts.pending]: (state) => { state.status = 'pending'; },
},
// ->
extraReducers: (builder) => {
builder
.addCase(fetchPosts.pending, (state) => { state.status = 'pending'; });
},
```
- computed keys (`[thunk.fulfilled]`), string keys and plain keys become `addCase` calls, in order
- method shorthand (`[x](state) {}`) becomes a function expression
- an object with spreads or getters is left alone
- JavaScript and TypeScript files
Not handled: the other RTK 2 changes (`configureStore`'s array `middleware`,
`getDefaultMiddleware`'s import, `createAsyncThunk` typing). Run the tests.
```sh
npx codemod run @apiweiser/reduxjs_toolkit-1-to-2 --target .
```