-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fill out v1.9 remaining docs #2804
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9fc1ecc
Update Yarn to 3.2.4 to fix Docusaurus install issues
markerikson 8bd8a40
Update Docusaurus to 2.1.0 and fix React types packages
markerikson af63a4f
Export `defaultSerializeQueryArgs`
markerikson 9faae2a
Document `serializeQueryArgs` option
markerikson 5ff666f
Document `merge` option
markerikson d567ef3
Document `upsertQueryData`
markerikson 71003b8
Document `forceRefetch` option
markerikson 85a3d0d
Rework fetchBaseQuery API ref and document new options
markerikson bcddc68
Add codemods page
markerikson 6763f7b
Turn off `skipLibCheck` for typetests
markerikson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
id: codemods | ||
title: Codemods | ||
sidebar_label: Codemods | ||
hide_title: true | ||
--- | ||
|
||
| ||
|
||
# Codemods | ||
|
||
Per [the description in `1.9.0-alpha.0`](https://github.com/reduxjs/redux-toolkit/releases/tag/v1.9.0-alpha.0), we plan to remove the "object" argument from `createReducer` and `createSlice.extraReducers` in the future RTK 2.0 major version. In `1.9.0-alpha.0`, we added a one-shot runtime warning to each of those APIs. | ||
|
||
To simplify upgrading codebases, we've published a set of codemods that will automatically transform the deprecated "object" syntax into the equivalent "builder" syntax. | ||
|
||
The codemods package is available on NPM as [**`@reduxjs/rtk-codemods`**](https://www.npmjs.com/package/@reduxjs/rtk-codemods). It currently contains two codemods: `createReducerBuilder` and `createSliceBuilder`. | ||
|
||
To run the codemods against your codebase, run `npx @reduxjs/rtk-codemods <TRANSFORM NAME> path/of/files/ or/some**/*glob.js`. | ||
|
||
Examples: | ||
|
||
```bash | ||
npx @reduxjs/rtk-codemods createReducerBuilder ./src | ||
|
||
npx @reduxjs/rtk-codemods createSliceBuilder ./packages/my-app/**/*.ts | ||
``` | ||
|
||
We also recommend re-running Prettier on the codebase before committing the changes. | ||
|
||
**These codemods _should_ work, but we would greatly appreciate testing and feedback on more real-world codebases!** | ||
|
||
Before: | ||
|
||
```js | ||
createReducer(initialState, { | ||
[todoAdded1a]: (state, action) => { | ||
// stuff | ||
}, | ||
[todoAdded1b]: (state, action) => action.payload, | ||
}) | ||
|
||
const slice1 = createSlice({ | ||
name: 'a', | ||
initialState: {}, | ||
extraReducers: { | ||
[todoAdded1a]: (state, action) => { | ||
// stuff | ||
}, | ||
[todoAdded1b]: (state, action) => action.payload, | ||
}, | ||
}) | ||
``` | ||
|
||
After: | ||
|
||
```js | ||
createReducer(initialState, (builder) => { | ||
builder.addCase(todoAdded1a, (state, action) => { | ||
// stuff | ||
}) | ||
|
||
builder.addCase(todoAdded1b, (state, action) => action.payload) | ||
}) | ||
|
||
const slice1 = createSlice({ | ||
name: 'a', | ||
initialState: {}, | ||
|
||
extraReducers: (builder) => { | ||
builder.addCase(todoAdded1a, (state, action) => { | ||
// stuff | ||
}) | ||
|
||
builder.addCase(todoAdded1b, (state, action) => action.payload) | ||
}, | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the value being upserted is
undefined
, will it remove the cache key entirely? If not, is there a way to remove a cache entry entirely? (ie, likeinvalidateTags
, but without triggering a refetch)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ggaabe : no, it would replace the
.data
field withundefined
. It's the value, not the key.There isn't currently a way to remove one, but a few folks have asked for something like this. Could you comment over in #2820 and describe when and why you might want to do that?