Skip to content

Commit a6dc3cf

Browse files
authored
Merge pull request #1258 from Shrugsy/chore/deprecate-getDefaultMiddleware-export
🗑 📝 Deprecate getDefaultMiddleware export
2 parents bbdac06 + fd2ddfc commit a6dc3cf

File tree

6 files changed

+28
-46
lines changed

6 files changed

+28
-46
lines changed

docs/api/configureStore.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ want added to the store. `configureStore` will automatically pass those to `appl
8989
If not provided, `configureStore` will call `getDefaultMiddleware` and use the
9090
array of middleware functions it returns.
9191

92-
Alternately, you may pass a callback function that will receive `getDefaultMiddleware` as its argument,
93-
and should return a middleware array. This lets you skip importing `getDefaultMiddleware` separately. If using TypeScript, prefer using this syntax, as we provide a more strongly-typed version of `getDefaultMiddleware` that will correctly
94-
retain the types of the provided middleware when constructing the store.
92+
Where you wish to add onto or customize the default middleware,
93+
you may pass a callback function that will receive `getDefaultMiddleware` as its argument,
94+
and should return a middleware array.
9595

9696
For more details on how the `middleware` parameter works and the list of middleware that are added by default, see the
9797
[`getDefaultMiddleware` docs page](./getDefaultMiddleware.mdx).

docs/api/getDefaultMiddleware.mdx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,6 @@ const store = configureStore({
6464

6565
It is preferrable to use the chainable `.concat(...)` and `.prepend(...)` methods of the returned `MiddlewareArray` instead of the array spread operator, as the latter can lose valuable type information under some circumstances.
6666

67-
## getDefaultMiddleware import
68-
69-
While the callback notation with `configureStore` shown in the last example is the recommended way of using `getDefaultMiddleware`, it can also be imported to be used independently from 'configureStore':
70-
71-
```ts
72-
// file: reducer.ts noEmit
73-
74-
export default function rootReducer(state = {}, action: any) {
75-
return state
76-
}
77-
78-
// file: store.ts
79-
import { getDefaultMiddleware } from '@reduxjs/toolkit'
80-
81-
interface State {
82-
// ...
83-
}
84-
85-
const middlewares = getDefaultMiddleware<State>()
86-
```
87-
88-
The benefit of using the callback notation is that the `State` type is already pre-bound, which might prevent circular type references when trying to specify generics by hand.
89-
9067
## Included Default Middleware
9168

9269
### Development

docs/rtk-query/usage/automated-refetching.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ In order to provide stronger control over invalidating the appropriate data, you
388388
389389
The matrix below shows examples of which invalidated tags will affect and invalidate which provided tags:
390390
391-
<table class="checkbox-table">
391+
<table className="checkbox-table">
392392
<thead>
393393
<tr>
394394
<th className="diagonal-cell">

docs/usage/usage-guide.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ export default function configureAppStore(preloadedState) {
139139
}
140140
```
141141

142-
If you provide the `middleware` argument, `configureStore` will only use whatever middleware you've listed. If you want to have some custom middleware _and_ the defaults all together, you can call [`getDefaultMiddleware`](../api/getDefaultMiddleware.mdx) and include the results in the `middleware` array you provide.
142+
If you provide the `middleware` argument, `configureStore` will only use whatever middleware you've listed.
143+
If you want to have some custom middleware _and_ the defaults all together, you can use the callback notation,
144+
call [`getDefaultMiddleware`](../api/getDefaultMiddleware.mdx) and include the results in the `middleware` array you return.
143145

144146
## Writing Reducers
145147

@@ -1033,16 +1035,17 @@ The [serializability dev check middleware](../api/serializabilityMiddleware.mdx)
10331035
```js
10341036
configureStore({
10351037
//...
1036-
middleware: getDefaultMiddleware({
1037-
serializableCheck: {
1038-
// Ignore these action types
1039-
ignoredActions: ['your/action/type'],
1040-
// Ignore these field paths in all actions
1041-
ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
1042-
// Ignore these paths in the state
1043-
ignoredPaths: ['items.dates'],
1044-
},
1045-
}),
1038+
middleware: (getDefaultMiddleware) =>
1039+
getDefaultMiddleware({
1040+
serializableCheck: {
1041+
// Ignore these action types
1042+
ignoredActions: ['your/action/type'],
1043+
// Ignore these field paths in all actions
1044+
ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
1045+
// Ignore these paths in the state
1046+
ignoredPaths: ['items.dates'],
1047+
},
1048+
}),
10461049
})
10471050
```
10481051

@@ -1051,7 +1054,7 @@ configureStore({
10511054
If using Redux-Persist, you should specifically ignore all the action types it dispatches:
10521055

10531056
```jsx
1054-
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
1057+
import { configureStore } from '@reduxjs/toolkit'
10551058
import {
10561059
persistStore,
10571060
persistReducer,
@@ -1078,11 +1081,12 @@ const persistedReducer = persistReducer(persistConfig, rootReducer)
10781081

10791082
const store = configureStore({
10801083
reducer: persistedReducer,
1081-
middleware: getDefaultMiddleware({
1082-
serializableCheck: {
1083-
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
1084-
},
1085-
}),
1084+
middleware: (getDefaultMiddleware) =>
1085+
getDefaultMiddleware({
1086+
serializableCheck: {
1087+
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
1088+
},
1089+
}),
10861090
})
10871091

10881092
let persistor = persistStore(store)

docs/usage/usage-with-typescript.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ The type of the `dispatch` function type will be directly inferred from the `mid
8989

9090
As TypeScript often widens array types when combining arrays using the spread operator, we suggest using the `.concat(...)` and `.prepend(...)` methods of the `MiddlewareArray` returned by `getDefaultMiddleware()`.
9191

92-
Also, we suggest using the callback notation for the `middleware` option to get a correctly pre-typed version of `getDefaultMiddleware` that does not require you to specify any generics by hand.
93-
9492
```ts
9593
import { configureStore } from '@reduxjs/toolkit'
9694
import additionalMiddleware from 'additional-middleware'

packages/toolkit/src/getDefaultMiddleware.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export function curryGetDefaultMiddleware<
6363
* @return The default middleware used by `configureStore()`.
6464
*
6565
* @public
66+
*
67+
* @deprecated Prefer to use the callback notation for the `middleware` option in `configureStore`
68+
* to access a pre-typed `getDefaultMiddleware` instead.
6669
*/
6770
export function getDefaultMiddleware<
6871
S = any,

0 commit comments

Comments
 (0)