new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Redux Toolkit · API · all subjects

codemods

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Running codemods command syntax

Codemods are run using the command: npx @reduxjs/rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js

RTK 2.0 removed object argument from createReducer and createSlice.extraReducers

In RTK 2.0, the object argument was removed from createReducer and createSlice.extraReducers. A new optional form of createSlice.reducers was added that uses a callback instead of an object.

@reduxjs/rtk-codemods package available on NPM

The codemods package is available on NPM as @reduxjs/rtk-codemods and contains automated transformations to upgrade Redux Toolkit codebases from deprecated object syntax to builder syntax for RTK 2.0.

createReducerBuilder codemod

The createReducerBuilder codemod migrates createReducer calls that use the removed object syntax to the builder callback syntax.

createSliceReducerBuilder codemod

The createSliceReducerBuilder codemod migrates createSlice calls that use the still-standard object syntax for reducers to the optional new builder callback syntax, including uses of prepared reducers.

createReducer object syntax to builder syntax migration example

Before: createReducer(initialState, { [todoAdded1a]: (state, action) => { // stuff }, [todoAdded1b]: (state, action) => action.payload, }) After: createReducer(initialState, (builder) => { builder.addCase(todoAdded1a, (state, action) => { // stuff }) builder.addCase(todoAdded1b, (state, action) => action.payload) })

createSlice extraReducers object syntax to builder syntax migration example

Before: const slice1 = createSlice({ name: 'a', initialState: {}, extraReducers: { [todoAdded1a]: (state, action) => { // stuff }, [todoAdded1b]: (state, action) => action.payload, }, }) After: const slice1 = createSlice({ name: 'a', initialState: {}, extraReducers: (builder) => { builder.addCase(todoAdded1a, (state, action) => { // stuff }) builder.addCase(todoAdded1b, (state, action) => action.payload) }, })

RTK codemods available for migration

Redux Toolkit provides codemods via the @reduxjs/rtk-codemods package to automatically transform deprecated syntax to the new form. Use 'npx @reduxjs/rtk-codemods createReducerBuilder ./src' to migrate createReducer object syntax to builder form, or 'npx @reduxjs/rtk-codemods createSliceBuilder ./src' to migrate createSlice reducers.

Use codemods for mechanical RTK migrations

The @reduxjs/rtk-codemods package provides automated transformations: createSliceBuilder converts legacy reducers to createSlice, and createReducerBuilder converts createReducer calls. Run these codemods on legacy files, then review and finish semantic cleanup by hand. Example commands: npx @reduxjs/rtk-codemods createSliceBuilder src/features/posts/postsSlice.ts or npx @reduxjs/rtk-codemods createReducerBuilder src/features/posts/postsReducer.ts.

Give your agent this brain