From f03bfbffed8a6490b4bc6b81c5ada271dd0e0943 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sat, 29 May 2021 22:32:16 -0400 Subject: [PATCH 1/3] Remove dead prepare script --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 14c78b26a8..6fb3d90ad6 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"", "format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"", "lint": "eslint src examples", - "prepare": "true", "test": "jest --runInBand", "type-tests": "yarn tsc -p src/tests && yarn tsc -p src/query/tests" }, @@ -125,4 +124,4 @@ "doc": "docs", "example": "example" } -} \ No newline at end of file +} From 0620d7899f9b3685bf0d8ce3d02276cd9011656e Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sat, 29 May 2021 22:32:46 -0400 Subject: [PATCH 2/3] Work around Docusaurus bug to show headers again --- docs/api/configureStore.mdx | 2 + docs/api/createAction.mdx | 14 +++--- docs/api/createAsyncThunk.mdx | 44 ++++++++-------- docs/api/createEntityAdapter.mdx | 50 ++++++++++--------- docs/api/createReducer.mdx | 36 ++++++------- docs/api/createSelector.mdx | 6 ++- docs/api/createSlice.mdx | 40 ++++++++------- docs/api/getDefaultMiddleware.mdx | 16 +++--- docs/api/immutabilityMiddleware.mdx | 28 ++++++----- docs/api/matching-utilities.mdx | 22 +++++--- docs/api/otherExports.mdx | 4 +- docs/api/serializabilityMiddleware.mdx | 10 ++-- docs/introduction/getting-started.md | 2 + docs/rtk-query/api/ApiProvider.mdx | 2 + docs/rtk-query/api/createApi.mdx | 2 + .../api/created-api/cache-management.mdx | 2 + .../api/created-api/code-splitting.mdx | 2 + docs/rtk-query/api/created-api/endpoints.mdx | 2 + docs/rtk-query/api/created-api/hooks.mdx | 2 + docs/rtk-query/api/created-api/overview.mdx | 2 + .../api/created-api/redux-integration.mdx | 6 ++- docs/rtk-query/api/fetchBaseQuery.mdx | 4 +- docs/rtk-query/api/setupListeners.mdx | 2 + docs/rtk-query/comparison.md | 2 + docs/rtk-query/overview.md | 2 + docs/rtk-query/usage-with-typescript.mdx | 2 + docs/rtk-query/usage/cached-data.mdx | 2 + docs/rtk-query/usage/code-generation.mdx | 9 +++- docs/rtk-query/usage/code-splitting.mdx | 6 ++- docs/rtk-query/usage/conditional-fetching.mdx | 2 + .../usage/customizing-create-api.mdx | 2 + docs/rtk-query/usage/customizing-queries.mdx | 2 + docs/rtk-query/usage/error-handling.mdx | 14 ++++-- docs/rtk-query/usage/examples.mdx | 2 + .../usage/migrating-to-rtk-query.mdx | 2 + docs/rtk-query/usage/mutations.mdx | 2 + docs/rtk-query/usage/optimistic-updates.mdx | 2 + docs/rtk-query/usage/pagination.mdx | 2 + docs/rtk-query/usage/polling.mdx | 2 + docs/rtk-query/usage/prefetching.mdx | 2 + docs/rtk-query/usage/queries.mdx | 2 + docs/rtk-query/usage/streaming-updates.mdx | 2 + docs/tutorials/overview.md | 2 + docs/tutorials/quick-start.md | 2 + docs/tutorials/rtk-query.mdx | 2 + docs/tutorials/typescript.md | 2 + docs/usage/immer-reducers.md | 2 + docs/usage/usage-guide.md | 2 + docs/usage/usage-with-typescript.md | 2 + 49 files changed, 243 insertions(+), 132 deletions(-) diff --git a/docs/api/configureStore.mdx b/docs/api/configureStore.mdx index cdb3a9c556..fb0e40a70a 100644 --- a/docs/api/configureStore.mdx +++ b/docs/api/configureStore.mdx @@ -5,6 +5,8 @@ sidebar_label: configureStore hide_title: true --- +  + # `configureStore` A friendly abstraction over the standard Redux `createStore` function that adds good defaults diff --git a/docs/api/createAction.mdx b/docs/api/createAction.mdx index e5de5886a9..b700e2f21b 100644 --- a/docs/api/createAction.mdx +++ b/docs/api/createAction.mdx @@ -5,6 +5,8 @@ sidebar_label: createAction hide_title: true --- +  + # `createAction` A helper function for defining a Redux [action](https://redux.js.org/basics/actions) type and creator. @@ -21,7 +23,7 @@ const INCREMENT = 'counter/increment' function increment(amount: number) { return { type: INCREMENT, - payload: amount + payload: amount, } } @@ -63,8 +65,8 @@ const addTodo = createAction('todos/add', function prepare(text: string) { payload: { text, id: nanoid(), - createdAt: new Date().toISOString() - } + createdAt: new Date().toISOString(), + }, } }) @@ -95,7 +97,7 @@ import { createAction, createReducer } from '@reduxjs/toolkit' const increment = createAction('counter/increment') const decrement = createAction('counter/decrement') -const counterReducer = createReducer(0, builder => { +const counterReducer = createReducer(0, (builder) => { builder.addCase(increment, (state, action) => state + action.payload) builder.addCase(decrement, (state, action) => state - action.payload) }) @@ -133,7 +135,7 @@ const counterReducer = createReducer(0, { [increment]: (state, action) => state + action.payload, // You would need to use the action type explicitly instead. - [INCREMENT]: (state, action) => state + action.payload + [INCREMENT]: (state, action) => state + action.payload, }) ``` @@ -178,7 +180,7 @@ const increment = createAction('INCREMENT') export const epic = (actions$: Observable) => actions$.pipe( filter(increment.match), - map(action => { + map((action) => { // action.payload can be safely used as number here (and will also be correctly inferred by TypeScript) // ... }) diff --git a/docs/api/createAsyncThunk.mdx b/docs/api/createAsyncThunk.mdx index e4c8a34a43..3e84c65fcb 100644 --- a/docs/api/createAsyncThunk.mdx +++ b/docs/api/createAsyncThunk.mdx @@ -5,6 +5,8 @@ sidebar_label: createAsyncThunk hide_title: true --- +  + # `createAsyncThunk` ## Overview @@ -42,8 +44,8 @@ const usersSlice = createSlice({ [fetchUserById.fulfilled]: (state, action) => { // Add user to the state array state.entities.push(action.payload) - } - } + }, + }, }) // Later, dispatch the thunk as needed in the app @@ -193,10 +195,10 @@ To handle these actions in your reducers, reference the action creators in `crea ```js {2,6,14,23} const reducer1 = createReducer(initialState, { - [fetchUserById.fulfilled]: (state, action) => {} + [fetchUserById.fulfilled]: (state, action) => {}, }) -const reducer2 = createReducer(initialState, builder => { +const reducer2 = createReducer(initialState, (builder) => { builder.addCase(fetchUserById.fulfilled, (state, action) => {}) }) @@ -205,17 +207,17 @@ const reducer3 = createSlice({ initialState, reducers: {}, extraReducers: { - [fetchUserById.fulfilled]: (state, action) => {} - } + [fetchUserById.fulfilled]: (state, action) => {}, + }, }) const reducer4 = createSlice({ name: 'users', initialState, reducers: {}, - extraReducers: builder => { + extraReducers: (builder) => { builder.addCase(fetchUserById.fulfilled, (state, action) => {}) - } + }, }) ``` @@ -244,8 +246,8 @@ import { unwrapResult } from '@reduxjs/toolkit' const onClick = () => { dispatch(fetchUserById(userId)) .then(unwrapResult) - .then(originalPromiseResult => {}) - .catch(rejectedValueOrSerializedError => {}) + .then((originalPromiseResult) => {}) + .catch((rejectedValueOrSerializedError) => {}) } ``` @@ -310,7 +312,7 @@ const fetchUserById = createAsyncThunk( // Already fetched or in progress, don't need to re-fetch return false } - } + }, } ) ``` @@ -372,7 +374,7 @@ const fetchUserById = createAsyncThunk( 'users/fetchById', async (userId: string, thunkAPI) => { const response = await fetch(`https://reqres.in/api/users/${userId}`, { - signal: thunkAPI.signal + signal: thunkAPI.signal, }) return await response.json() } @@ -426,7 +428,7 @@ const fetchUserById = createAsyncThunk( source.cancel() }) const response = await axios.get(`https://reqres.in/api/users/${userId}`, { - cancelToken: source.token + cancelToken: source.token, }) return response.data } @@ -459,7 +461,7 @@ const usersSlice = createSlice({ entities: [], loading: 'idle', currentRequestId: undefined, - error: null + error: null, }, reducers: {}, extraReducers: { @@ -484,15 +486,15 @@ const usersSlice = createSlice({ state.error = action.error state.currentRequestId = undefined } - } - } + }, + }, }) const UsersComponent = () => { - const { users, loading, error } = useSelector(state => state.users) + const { users, loading, error } = useSelector((state) => state.users) const dispatch = useDispatch() - const fetchOneUser = async userId => { + const fetchOneUser = async (userId) => { try { const resultAction = await dispatch(fetchUserById(userId)) const user = unwrapResult(resultAction) @@ -577,14 +579,14 @@ interface UsersState { const initialState = { entities: {}, - error: null + error: null, } as UsersState const usersSlice = createSlice({ name: 'users', initialState, reducers: {}, - extraReducers: builder => { + extraReducers: (builder) => { // The `builder` callback form is used here because it provides correctly typed reducers from the action creators builder.addCase(updateUser.fulfilled, (state, { payload }) => { state.entities[payload.id] = payload @@ -597,7 +599,7 @@ const usersSlice = createSlice({ state.error = action.error.message } }) - } + }, }) export default usersSlice.reducer diff --git a/docs/api/createEntityAdapter.mdx b/docs/api/createEntityAdapter.mdx index 0a7b96eb4e..72eade56eb 100644 --- a/docs/api/createEntityAdapter.mdx +++ b/docs/api/createEntityAdapter.mdx @@ -5,6 +5,8 @@ sidebar_label: createEntityAdapter hide_title: true --- +  + # `createEntityAdapter` ## Overview @@ -39,16 +41,16 @@ Sample usage: import { createEntityAdapter, createSlice, - configureStore + configureStore, } from '@reduxjs/toolkit' type Book = { bookId: string; title: string } const booksAdapter = createEntityAdapter({ // Assume IDs are stored in a field other than `book.id` - selectId: book => book.bookId, + selectId: (book) => book.bookId, // Keep the "all IDs" array sorted based on book titles - sortComparer: (a, b) => a.title.localeCompare(b.title) + sortComparer: (a, b) => a.title.localeCompare(b.title), }) const booksSlice = createSlice({ @@ -61,14 +63,14 @@ const booksSlice = createSlice({ booksReceived(state, action) { // Or, call them as "mutating" helpers in a case reducer booksAdapter.setAll(state, action.payload.books) - } - } + }, + }, }) const store = configureStore({ reducer: { - books: booksSlice.reducer - } + books: booksSlice.reducer, + }, }) type RootState = ReturnType @@ -78,7 +80,7 @@ console.log(store.getState().books) // Can create a set of memoized selectors based on the location of this entity state const booksSelectors = booksAdapter.getSelectors( - state => state.books + (state) => state.books ) // And then use the selectors to retrieve values @@ -243,14 +245,14 @@ It accepts an optional object as an argument. The fields in that object will be const booksSlice = createSlice({ name: 'books', initialState: booksAdapter.getInitialState({ - loading: 'idle' + loading: 'idle', }), reducers: { booksLoadingStarted(state, action) { // Can update the additional state field state.loading = 'pending' - } - } + }, + }, }) ``` @@ -276,12 +278,12 @@ For example, the entity state for a `Book` type might be kept in the Redux state ```js const store = configureStore({ reducer: { - books: booksReducer - } + books: booksReducer, + }, }) const simpleSelectors = booksAdapter.getSelectors() -const globalizedSelectors = booksAdapter.getSelectors(state => state.books) +const globalizedSelectors = booksAdapter.getSelectors((state) => state.books) // Need to manually pass the correct entity state object in to this selector const bookIds = simpleSelectors.selectIds(store.getState().books) @@ -306,19 +308,19 @@ Exercising several of the CRUD methods and selectors: import { createEntityAdapter, createSlice, - configureStore + configureStore, } from '@reduxjs/toolkit' // Since we don't provide `selectId`, it defaults to assuming `entity.id` is the right field const booksAdapter = createEntityAdapter({ // Keep the "all IDs" array sorted based on book titles - sortComparer: (a, b) => a.title.localeCompare(b.title) + sortComparer: (a, b) => a.title.localeCompare(b.title), }) const booksSlice = createSlice({ name: 'books', initialState: booksAdapter.getInitialState({ - loading: 'idle' + loading: 'idle', }), reducers: { // Can pass adapter functions directly as case reducers. Because we're passing this @@ -336,28 +338,28 @@ const booksSlice = createSlice({ state.loading = 'idle' } }, - bookUpdated: booksAdapter.updateOne - } + bookUpdated: booksAdapter.updateOne, + }, }) const { bookAdded, booksLoading, booksReceived, - bookUpdated + bookUpdated, } = booksSlice.actions const store = configureStore({ reducer: { - books: booksSlice.reducer - } + books: booksSlice.reducer, + }, }) // Check the initial state: console.log(store.getState().books) // {ids: [], entities: {}, loading: 'idle' } -const booksSelectors = booksAdapter.getSelectors(state => state.books) +const booksSelectors = booksAdapter.getSelectors((state) => state.books) store.dispatch(bookAdded({ id: 'a', title: 'First' })) console.log(store.getState().books) @@ -371,7 +373,7 @@ console.log(store.getState().books) store.dispatch( booksReceived([ { id: 'b', title: 'Book 3' }, - { id: 'c', title: 'Book 2' } + { id: 'c', title: 'Book 2' }, ]) ) diff --git a/docs/api/createReducer.mdx b/docs/api/createReducer.mdx index 89811916c1..eb5821671e 100644 --- a/docs/api/createReducer.mdx +++ b/docs/api/createReducer.mdx @@ -5,6 +5,8 @@ sidebar_label: createReducer hide_title: true --- +  + # `createReducer()` ## Overview @@ -54,7 +56,7 @@ const incrementByAmount = createAction('counter/incrementByAmount') const initialState = { value: 0 } as CounterState -const counterReducer = createReducer(initialState, builder => { +const counterReducer = createReducer(initialState, (builder) => { builder .addCase(increment, (state, action) => { state.value++ @@ -128,7 +130,7 @@ so we recommend the "builder callback" notation in most cases. The most readable approach to define matcher cases and default cases is by using the `builder.addMatcher` and `builder.addDefaultCase` methods described above, but it is also possible to use these with the object notation by passing an array of `{matcher, reducer}` objects as the third argument, and a default case reducer as the fourth argument: ```js -const isStringPayloadAction = action => typeof action.payload === 'string' +const isStringPayloadAction = (action) => typeof action.payload === 'string' const lengthOfAllStringsReducer = createReducer( // initial state @@ -143,11 +145,11 @@ const lengthOfAllStringsReducer = createReducer( matcher: isStringPayloadAction, reducer(state, action) { state.strLen += action.payload.length - } - } + }, + }, ], // default reducer - state => { + (state) => { state.nonStringActions++ } ) @@ -168,7 +170,7 @@ interface Todo { const addTodo = createAction('todos/add') const toggleTodo = createAction('todos/toggle') -const todosReducer = createReducer([] as Todo[], builder => { +const todosReducer = createReducer([] as Todo[], (builder) => { builder .addCase(addTodo, (state, action) => { const todo = action.payload @@ -180,7 +182,7 @@ const todosReducer = createReducer([] as Todo[], builder => { return [ ...state.slice(0, index), { ...todo, completed: !todo.completed }, - ...state.slice(index + 1) + ...state.slice(index + 1), ] }) }) @@ -201,7 +203,7 @@ interface Todo { const addTodo = createAction('todos/add') const toggleTodo = createAction('todos/toggle') -const todosReducer = createReducer([] as Todo[], builder => { +const todosReducer = createReducer([] as Todo[], (builder) => { builder .addCase(addTodo, (state, action) => { // This push() operation gets translated into the same @@ -231,7 +233,7 @@ interface Todo { const toggleTodo = createAction('todos/toggle') -const todosReducer = createReducer([] as Todo[], builder => { +const todosReducer = createReducer([] as Todo[], (builder) => { builder.addCase(toggleTodo, (state, action) => { const index = action.payload const todo = state[index] @@ -265,16 +267,16 @@ The executing reducers form a pipeline, and each of them will receive the output ```ts import { createReducer } from '@reduxjs/toolkit' -const reducer = createReducer(0, builder => { +const reducer = createReducer(0, (builder) => { builder - .addCase('increment', state => state + 1) + .addCase('increment', (state) => state + 1) .addMatcher( - action => action.startsWith('i'), - state => state * 5 + (action) => action.startsWith('i'), + (state) => state * 5 ) .addMatcher( - action => action.endsWith('t'), - state => state + 2 + (action) => action.endsWith('t'), + (state) => state + 2 ) }) @@ -302,7 +304,7 @@ const slice = createSlice({ console.log('before', current(state)) state.push(action.payload) console.log('after', current(state)) - } - } + }, + }, }) ``` diff --git a/docs/api/createSelector.mdx b/docs/api/createSelector.mdx index a97e3e70ba..ec88f8fd3d 100644 --- a/docs/api/createSelector.mdx +++ b/docs/api/createSelector.mdx @@ -5,6 +5,8 @@ sidebar_label: createSelector hide_title: true --- +  + # `createSelector` The `createSelector` utility from the [Reselect library](https://github.com/reduxjs/reselect), re-exported for ease of use. @@ -37,10 +39,10 @@ Example: ```js const selectSelf = (state: State) => state -const unsafeSelector = createSelector(selectSelf, state => state.value) +const unsafeSelector = createSelector(selectSelf, (state) => state.value) const draftSafeSelector = createDraftSafeSelector( selectSelf, - state => state.value + (state) => state.value ) // in your reducer: diff --git a/docs/api/createSlice.mdx b/docs/api/createSlice.mdx index 97ae8d59a0..c5777e185e 100644 --- a/docs/api/createSlice.mdx +++ b/docs/api/createSlice.mdx @@ -5,6 +5,8 @@ sidebar_label: createSlice hide_title: true --- +  + # `createSlice` A function that accepts an initial state, an object full of reducer functions, and a "slice name", @@ -36,8 +38,8 @@ const counterSlice = createSlice({ }, incrementByAmount(state, action: PayloadAction) { state.value += action.payload - } - } + }, + }, }) export const { increment, decrement, incrementByAmount } = counterSlice.actions @@ -93,8 +95,8 @@ const counterSlice = createSlice({ name: 'counter', initialState: 0, reducers: { - increment: state => state + 1 - } + increment: (state) => state + 1, + }, }) // Will handle the action type `'counter/increment'` ``` @@ -123,9 +125,9 @@ const todosSlice = createSlice({ prepare: (text: string) => { const id = nanoid() return { payload: { id, text } } - } - } - } + }, + }, + }, }) ``` @@ -175,8 +177,8 @@ createSlice({ [incrementBy]: (state, action) => { return state + action.payload }, - 'some/other/action': (state, action) => {} - } + 'some/other/action': (state, action) => {}, + }, }) ``` @@ -227,22 +229,22 @@ const counter = createSlice({ name: 'counter', initialState: 0 as number, reducers: { - increment: state => state + 1, - decrement: state => state - 1, + increment: (state) => state + 1, + decrement: (state) => state - 1, multiply: { reducer: (state, action: PayloadAction) => state * action.payload, - prepare: (value?: number) => ({ payload: value || 2 }) // fallback if the payload is a falsy value - } + prepare: (value?: number) => ({ payload: value || 2 }), // fallback if the payload is a falsy value + }, }, // "builder callback API", recommended for TypeScript users - extraReducers: builder => { + extraReducers: (builder) => { builder.addCase(incrementBy, (state, action) => { return state + action.payload }) builder.addCase(decrementBy, (state, action) => { return state - action.payload }) - } + }, }) const user = createSlice({ @@ -251,7 +253,7 @@ const user = createSlice({ reducers: { setUserName: (state, action) => { state.name = action.payload // mutate the state all you want with immer - } + }, }, // "map object API" extraReducers: { @@ -261,13 +263,13 @@ const user = createSlice({ action /* action will be inferred as "any", as the map notation does not contain type information */ ) => { state.age += 1 - } - } + }, + }, }) const reducer = combineReducers({ counter: counter.reducer, - user: user.reducer + user: user.reducer, }) const store = createStore(reducer) diff --git a/docs/api/getDefaultMiddleware.mdx b/docs/api/getDefaultMiddleware.mdx index f7d0d14a92..9a3ade5ffd 100644 --- a/docs/api/getDefaultMiddleware.mdx +++ b/docs/api/getDefaultMiddleware.mdx @@ -5,6 +5,8 @@ sidebar_label: getDefaultMiddleware hide_title: true --- +  + # `getDefaultMiddleware` Returns an array containing the default list of middleware. @@ -15,7 +17,7 @@ By default, [`configureStore`](./configureStore.mdx) adds some middleware to the ```js const store = configureStore({ - reducer: rootReducer + reducer: rootReducer, }) // Store has middleware added, because the middleware list was not customized @@ -26,7 +28,7 @@ If you want to customize the list of middleware, you can supply an array of midd ```js const store = configureStore({ reducer: rootReducer, - middleware: [thunk, logger] + middleware: [thunk, logger], }) // Store specifically has the thunk and logger middleware applied @@ -54,7 +56,7 @@ import rootReducer from './reducer' const store = configureStore({ reducer: rootReducer, - middleware: getDefaultMiddleware => getDefaultMiddleware().concat(logger) + middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger), }) // Store has all of the default middleware added, _plus_ the logger middleware @@ -149,13 +151,13 @@ import { myCustomApiService } from './api' const store = configureStore({ reducer: rootReducer, - middleware: getDefaultMiddleware => + middleware: (getDefaultMiddleware) => getDefaultMiddleware({ thunk: { - extraArgument: myCustomApiService + extraArgument: myCustomApiService, }, - serializableCheck: false - }) + serializableCheck: false, + }), }) ``` diff --git a/docs/api/immutabilityMiddleware.mdx b/docs/api/immutabilityMiddleware.mdx index a4a6bb1847..299632b9ba 100644 --- a/docs/api/immutabilityMiddleware.mdx +++ b/docs/api/immutabilityMiddleware.mdx @@ -5,6 +5,8 @@ sidebar_label: Immutability Middleware hide_title: true --- +  + # Immutability Middleware A port of the [`redux-immutable-state-invariant`](https://github.com/leoasis/redux-immutable-state-invariant) middleware, customized for use with Redux Toolkit. Any detected mutations will be thrown as errors. @@ -61,10 +63,10 @@ export const exampleSlice = createSlice({ ignoredPath: 'single level', ignoredNested: { one: 'one', - two: 'two' - } + two: 'two', + }, }, - reducers: {} + reducers: {}, }) export default exampleSlice.reducer @@ -73,19 +75,19 @@ export default exampleSlice.reducer import { configureStore, - createImmutableStateInvariantMiddleware + createImmutableStateInvariantMiddleware, } from '@reduxjs/toolkit' import exampleSliceReducer from './exampleSlice' const immutableInvariantMiddleware = createImmutableStateInvariantMiddleware({ - ignoredPaths: ['ignoredPath', 'ignoredNested.one', 'ignoredNested.two'] + ignoredPaths: ['ignoredPath', 'ignoredNested.one', 'ignoredNested.two'], }) const store = configureStore({ reducer: exampleSliceReducer, // Note that this will replace all default middleware - middleware: [immutableInvariantMiddleware] + middleware: [immutableInvariantMiddleware], }) ``` @@ -103,10 +105,10 @@ export const exampleSlice = createSlice({ ignoredPath: 'single level', ignoredNested: { one: 'one', - two: 'two' - } + two: 'two', + }, }, - reducers: {} + reducers: {}, }) export default exampleSlice.reducer @@ -119,12 +121,12 @@ import exampleSliceReducer from './exampleSlice' const store = configureStore({ reducer: exampleSliceReducer, // Note that this will replace all default middleware - middleware: getDefaultMiddleware => + middleware: (getDefaultMiddleware) => getDefaultMiddleware({ immutableCheck: { - ignoredPaths: ['ignoredPath', 'ignoredNested.one', 'ignoredNested.two'] - } - }) + ignoredPaths: ['ignoredPath', 'ignoredNested.one', 'ignoredNested.two'], + }, + }), }) ``` diff --git a/docs/api/matching-utilities.mdx b/docs/api/matching-utilities.mdx index e975311d2c..576a7cd72f 100644 --- a/docs/api/matching-utilities.mdx +++ b/docs/api/matching-utilities.mdx @@ -5,6 +5,8 @@ sidebar_label: Matching Utilities hide_title: true --- +  + # Matching Utilities Redux Toolkit exports several type-safe action matching utilities that you can leverage when checking for specific kinds of actions. These are primarily useful for the `builder.addMatcher()` cases in `createSlice` and `createReducer`, as well as when writing custom middleware. @@ -141,7 +143,7 @@ First, let's examine an unnecessarily complex example: import { createAsyncThunk, createReducer, - PayloadAction + PayloadAction, } from '@reduxjs/toolkit' interface Data { @@ -176,7 +178,7 @@ interface ExampleState { const initialState = { isSpecial: false, - isInteresting: false + isInteresting: false, } as ExampleState export const isSpecialAndInterestingThunk = createAsyncThunk( @@ -184,13 +186,13 @@ export const isSpecialAndInterestingThunk = createAsyncThunk( () => { return { isSpecial: true, - isInteresting: true + isInteresting: true, } } ) // This has unnecessary complexity -const loadingReducer = createReducer(initialState, builder => { +const loadingReducer = createReducer(initialState, (builder) => { builder.addCase(isSpecialAndInterestingThunk.fulfilled, (state, action) => { if (isSpecial(action)) { state.isSpecial = true @@ -211,10 +213,10 @@ import { initialState, isSpecial, isInteresting, - Data + Data, } from '@virtual/matchers' // This is a fake pkg that provides the types shown above -const loadingReducer = createReducer(initialState, builder => { +const loadingReducer = createReducer(initialState, (builder) => { builder .addMatcher( isAllOf(isSpecialAndInterestingThunk.fulfilled, isSpecial), @@ -267,7 +269,13 @@ function someFunction(action: PayloadAction) {