diff --git a/docs/api/configureStore.mdx b/docs/api/configureStore.mdx index 6f37c89a80..e3199c6660 100644 --- a/docs/api/configureStore.mdx +++ b/docs/api/configureStore.mdx @@ -18,7 +18,7 @@ to the store setup for a better development experience. ```ts no-transpile type ConfigureEnhancersCallback = ( - defaultEnhancers: StoreEnhancer[] + defaultEnhancers: EnhancerArray<[StoreEnhancer]> ) => StoreEnhancer[] interface ConfigureStoreOptions< @@ -107,7 +107,8 @@ a list of the specific options that are available. Defaults to `true`. #### `trace` -The Redux DevTools Extension recently added [support for showing action stack traces](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/Features/Trace.md) that show exactly where each action was dispatched. + +The Redux DevTools Extension recently added [support for showing action stack traces](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/Features/Trace.md) that show exactly where each action was dispatched. Capturing the traces can add a bit of overhead, so the DevTools Extension allows users to configure whether action stack traces are captured by [setting the 'trace' argument](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md#trace). If the DevTools are enabled by passing `true` or an object, then `configureStore` will default to enabling capturing action stack traces in development mode only. @@ -129,7 +130,7 @@ If defined as a callback function, it will be called with the existing array of and should return a new array of enhancers. This is primarily useful for cases where a store enhancer needs to be added in front of `applyMiddleware`, such as `redux-first-router` or `redux-offline`. -Example: `enhancers: (defaultEnhancers) => [offline, ...defaultEnhancers]` will result in a final setup +Example: `enhancers: (defaultEnhancers) => defaultEnhancers.prepend(offline)` will result in a final setup of `[offline, applyMiddleware, devToolsExtension]`. ## Usage @@ -195,7 +196,7 @@ const preloadedState = { visibilityFilter: 'SHOW_COMPLETED', } -const debounceNotify = _.debounce(notify => notify()); +const debounceNotify = _.debounce((notify) => notify()) const store = configureStore({ reducer, diff --git a/docs/rtk-query/api/created-api/endpoints.mdx b/docs/rtk-query/api/created-api/endpoints.mdx index cbd847c8ae..5d49dd6d71 100644 --- a/docs/rtk-query/api/created-api/endpoints.mdx +++ b/docs/rtk-query/api/created-api/endpoints.mdx @@ -92,7 +92,7 @@ When dispatching an action creator, you're responsible for storing a reference t #### Example -```tsx title="initiate query example" +```tsx no-transpile title="initiate query example" import { useState } from 'react' import { useAppDispatch } from './store/hooks' import { api } from './services/api' @@ -119,7 +119,7 @@ function App() { } ``` -```tsx title="initiate mutation example" +```tsx no-transpile title="initiate mutation example" import { useState } from 'react' import { useAppDispatch } from './store/hooks' import { api, Post } from './services/api' @@ -187,7 +187,7 @@ Each call to `.select(someCacheKey)` returns a _new_ selector function instance. #### Example -```tsx title="select query example" +```tsx no-transpile title="select query example" import { useState, useMemo } from 'react' import { useAppDispatch, useAppSelector } from './store/hooks' import { api } from './services/api' @@ -198,9 +198,10 @@ function App() { // highlight-start // useMemo is used to only call `.select()` when required. // Each call will create a new selector function instance - const selectPost = useMemo(() => api.endpoints.getPost.select(postId), [ - postId, - ]) + const selectPost = useMemo( + () => api.endpoints.getPost.select(postId), + [postId] + ) const { data, isLoading } = useAppSelector(selectPost) // highlight-end @@ -223,7 +224,7 @@ function App() { } ``` -```tsx title="select mutation example" +```tsx no-transpile title="select mutation example" import { useState, useMemo } from 'react' import { skipToken } from '@reduxjs/toolkit/query' import { useAppDispatch, useAppSelector } from './store/hooks' diff --git a/docs/rtk-query/usage-with-typescript.mdx b/docs/rtk-query/usage-with-typescript.mdx index aef8eaba41..7107b83ab3 100644 --- a/docs/rtk-query/usage-with-typescript.mdx +++ b/docs/rtk-query/usage-with-typescript.mdx @@ -467,7 +467,7 @@ export const api = createApi({ export const { useGetPostQuery } = api ``` -```tsx title="Using skip in a component" +```tsx no-transpile title="Using skip in a component" import { useGetPostQuery } from './api' function MaybePost({ id }: { id?: number }) { @@ -486,7 +486,7 @@ While you might be able to convince yourself that the query won't be called unle RTK Query provides a `skipToken` export which can be used as an alternative to the `skip` option in order to skip queries, while remaining type-safe. When `skipToken` is passed as the query argument to `useQuery`, `useQueryState` or `useQuerySubscription`, it provides the same effect as setting `skip: true` in the query options, while also being a valid argument in scenarios where the `arg` might be undefined otherwise. -```tsx title="Using skipToken in a component" +```tsx no-transpile title="Using skipToken in a component" import { skipToken } from '@reduxjs/toolkit/query/react' import { useGetPostQuery } from './api' @@ -566,7 +566,7 @@ export interface SerializedError { When using `fetchBaseQuery`, the `error` property returned from a hook will have the type `FetchBaseQueryError | SerializedError | undefined`. If an error is present, you can access error properties after narrowing the type to either `FetchBaseQueryError` or `SerializedError`. -```tsx +```tsx no-transpile import { api } from './services/api' function PostDetail() { @@ -587,10 +587,9 @@ function PostDetail() {
(
* A utility function to create an action creator for the given action type
* string. The action creator accepts a single argument, which will be included
* in the action object as a field called payload. The action creator function
- * will also have its toString() overriden so that it returns the action type,
+ * will also have its toString() overridden so that it returns the action type,
* allowing it to be used in reducer logic that is looking for that action type.
*
* @param type The action type to use for created actions.
@@ -286,6 +286,16 @@ export function createAction(type: string, prepareAction?: Function): any {
return actionCreator
}
+/**
+ * Returns true if value is a plain object with a `type` property.
+ */
+export function isAction(action: unknown): action is Action =
(api) => (next) => (action) => {
+ if (!isAction(action)) {
+ // we only want to notify listeners for action objects
+ return next(action)
+ }
+
if (addListener.match(action)) {
return startListening(action.payload)
}
diff --git a/packages/toolkit/src/listenerMiddleware/tests/fork.test.ts b/packages/toolkit/src/listenerMiddleware/tests/fork.test.ts
index 2756e09f15..6d9e6abb56 100644
--- a/packages/toolkit/src/listenerMiddleware/tests/fork.test.ts
+++ b/packages/toolkit/src/listenerMiddleware/tests/fork.test.ts
@@ -367,7 +367,7 @@ describe('fork', () => {
},
})
- store.dispatch(increment)
+ store.dispatch(increment())
expect(await deferredResult).toBe(listenerCompleted)
})
diff --git a/packages/toolkit/src/query/react/ApiProvider.tsx b/packages/toolkit/src/query/react/ApiProvider.tsx
index 1f2bc7be27..abaef8c2cc 100644
--- a/packages/toolkit/src/query/react/ApiProvider.tsx
+++ b/packages/toolkit/src/query/react/ApiProvider.tsx
@@ -12,7 +12,7 @@ import type { Api } from '@reduxjs/toolkit/dist/query/apiTypes'
*
* @example
* ```tsx
- * // codeblock-meta title="Basic usage - wrap your App with ApiProvider"
+ * // codeblock-meta no-transpile title="Basic usage - wrap your App with ApiProvider"
* import * as React from 'react';
* import { ApiProvider } from '@reduxjs/toolkit/query/react';
* import { Pokemon } from './features/Pokemon';
diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts
index 9d89188514..28e2916bf7 100644
--- a/packages/toolkit/src/query/react/buildHooks.ts
+++ b/packages/toolkit/src/query/react/buildHooks.ts
@@ -140,7 +140,7 @@ interface UseQuerySubscriptionOptions extends SubscriptionOptions {
*
* @example
* ```tsx
- * // codeblock-meta title="Skip example"
+ * // codeblock-meta no-transpile title="Skip example"
* const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {
* const { data, error, status } = useGetPokemonByNameQuery(name, {
* skip,
diff --git a/packages/toolkit/src/tests/EnhancerArray.typetest.ts b/packages/toolkit/src/tests/EnhancerArray.typetest.ts
new file mode 100644
index 0000000000..56e89a30d1
--- /dev/null
+++ b/packages/toolkit/src/tests/EnhancerArray.typetest.ts
@@ -0,0 +1,135 @@
+import { configureStore } from '@reduxjs/toolkit'
+import type { StoreEnhancer } from 'redux'
+
+declare const expectType: