Skip to content

Commit 74d3baa

Browse files
committed
Assorted auto-formatting
1 parent deb9e82 commit 74d3baa

File tree

8 files changed

+191
-150
lines changed

8 files changed

+191
-150
lines changed

docs/api/configureStore.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const store = configureStore({ reducer: rootReducer })
150150

151151
### Full Example
152152

153-
```ts
153+
```ts no-transpile
154154
// file: todos/todosReducer.ts noEmit
155155
import { Reducer } from '@reduxjs/toolkit'
156156
declare const reducer: Reducer<{}>
@@ -175,29 +175,29 @@ import visibilityReducer from './visibility/visibilityReducer'
175175
176176
const reducer = {
177177
todos: todosReducer,
178-
visibility: visibilityReducer
178+
visibility: visibilityReducer,
179179
}
180180
181181
const preloadedState = {
182182
todos: [
183183
{
184184
text: 'Eat food',
185-
completed: true
185+
completed: true,
186186
},
187187
{
188188
text: 'Exercise',
189-
completed: false
190-
}
189+
completed: false,
190+
},
191191
],
192-
visibilityFilter: 'SHOW_COMPLETED'
192+
visibilityFilter: 'SHOW_COMPLETED',
193193
}
194194
195195
const store = configureStore({
196196
reducer,
197-
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(logger),
197+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
198198
devTools: process.env.NODE_ENV !== 'production',
199199
preloadedState,
200-
enhancers: [reduxBatch]
200+
enhancers: [reduxBatch],
201201
})
202202
203203
// The store has been created with these options:

docs/api/rtk-query/created-api/endpoints.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Each endpoint structure contains the following fields:
1313

1414
```ts
1515
type EndpointLogic = {
16-
initiate: InitiateRequestThunk;
17-
select: CreateCacheSelectorFactory;
18-
matchPending: Matcher<PendingAction>;
19-
matchFulfilled: Matcher<FulfilledAction>;
20-
matchRejected: Matcher<RejectedAction>;
21-
};
16+
initiate: InitiateRequestThunk
17+
select: CreateCacheSelectorFactory
18+
matchPending: Matcher<PendingAction>
19+
matchFulfilled: Matcher<FulfilledAction>
20+
matchRejected: Matcher<RejectedAction>
21+
}
2222
```
2323
2424
## `initiate`
@@ -93,17 +93,22 @@ When dispatching an action creator, you're responsible for storing a reference t
9393
#### Signature
9494

9595
```ts
96-
type CreateCacheSelectorFactory = QueryResultSelectorFactory | MutationResultSelectorFactory;
96+
type CreateCacheSelectorFactory =
97+
| QueryResultSelectorFactory
98+
| MutationResultSelectorFactory
9799

98100
type QueryResultSelectorFactory = (
99101
queryArg: QueryArg | SkipSelector
100-
) => (state: RootState) => QueryResultSelectorResult<Definition>;
102+
) => (state: RootState) => QueryResultSelectorResult<Definition>
101103

102-
type MutationResultSelectorFactory<Definition extends MutationDefinition<any, any, any, any>, RootState> = (
104+
type MutationResultSelectorFactory<
105+
Definition extends MutationDefinition<any, any, any, any>,
106+
RootState
107+
> = (
103108
requestId: string | SkipSelector
104-
) => (state: RootState) => MutationSubState<Definition> & RequestStatusFlags;
109+
) => (state: RootState) => MutationSubState<Definition> & RequestStatusFlags
105110

106-
type SkipSelector = typeof Symbol;
111+
type SkipSelector = typeof Symbol
107112
```
108113
109114
#### Description

docs/api/rtk-query/created-api/hooks.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ For example, if you had endpoints for `getPosts` and `updatePost`, these options
2525

2626
```ts title="Generated React Hook names"
2727
// Hooks attached to the endpoint definition
28-
const { data } = api.endpoints.getPosts.useQuery();
29-
const { data } = api.endpoints.updatePost.useMutation();
28+
const { data } = api.endpoints.getPosts.useQuery()
29+
const { data } = api.endpoints.updatePost.useMutation()
3030

3131
// Same hooks, but given unique names and attached to the API slice object
32-
const { data } = api.useGetPostsQuery();
33-
const [updatePost] = api.useUpdatePostMutation();
32+
const { data } = api.useGetPostsQuery()
33+
const [updatePost] = api.useUpdatePostMutation()
3434
```
3535

3636
The general format is `use(Endpointname)(Query|Mutation)` - `use` is prefixed, the first letter of your endpoint name is capitalized, then `Query` or `Mutation` is appended depending on the type.
@@ -42,36 +42,36 @@ The React-specific version of `createApi` also generates a `usePrefetch` hook, a
4242
#### Signature
4343

4444
```ts
45-
type UseQuery = (arg: any, options?: UseQueryOptions) => UseQueryResult;
45+
type UseQuery = (arg: any, options?: UseQueryOptions) => UseQueryResult
4646

4747
type UseQueryOptions = {
48-
pollingInterval?: number;
49-
refetchOnReconnect?: boolean;
50-
refetchOnFocus?: boolean;
51-
skip?: boolean;
52-
refetchOnMountOrArgChange?: boolean | number;
53-
selectFromResult?: QueryStateSelector;
54-
};
48+
pollingInterval?: number
49+
refetchOnReconnect?: boolean
50+
refetchOnFocus?: boolean
51+
skip?: boolean
52+
refetchOnMountOrArgChange?: boolean | number
53+
selectFromResult?: QueryStateSelector
54+
}
5555

5656
type UseQueryResult<T> = {
5757
// Base query state
58-
status: 'uninitialized' | 'pending' | 'fulfilled' | 'rejected'; // @deprecated - A string describing the query state
59-
originalArgs?: unknown; // Arguments passed to the query
60-
data?: T; // Returned result if present
61-
error?: unknown; // Error result if present
62-
requestId?: string; // A string generated by RTK Query
63-
endpointName?: string; // The name of the given endpoint for the query
64-
startedTimeStamp?: number; // Timestamp for when the query was initiated
65-
fulfilledTimeStamp?: number; // Timestamp for when the query was completed
66-
67-
isUninitialized: false; // Query has not started yet.
68-
isLoading: false; // Query is currently loading for the first time. No data yet.
69-
isFetching: false; // Query is currently fetching, but might have data from an earlier request.
70-
isSuccess: false; // Query has data from a successful load.
71-
isError: false; // Query is currently in an "error" state.
72-
73-
refetch: () => void; // A function to force refetch the query
74-
};
58+
status: 'uninitialized' | 'pending' | 'fulfilled' | 'rejected' // @deprecated - A string describing the query state
59+
originalArgs?: unknown // Arguments passed to the query
60+
data?: T // Returned result if present
61+
error?: unknown // Error result if present
62+
requestId?: string // A string generated by RTK Query
63+
endpointName?: string // The name of the given endpoint for the query
64+
startedTimeStamp?: number // Timestamp for when the query was initiated
65+
fulfilledTimeStamp?: number // Timestamp for when the query was completed
66+
67+
isUninitialized: false // Query has not started yet.
68+
isLoading: false // Query is currently loading for the first time. No data yet.
69+
isFetching: false // Query is currently fetching, but might have data from an earlier request.
70+
isSuccess: false // Query has data from a successful load.
71+
isError: false // Query is currently in an "error" state.
72+
73+
refetch: () => void // A function to force refetch the query
74+
}
7575
```
7676
7777
- **Parameters**
@@ -128,9 +128,11 @@ type UseMutationResult<Definition> = {
128128
The generated `UseMutation` hook will cause a component to re-render by default after the trigger callback is fired as it affects the properties of the result. If you want to call the trigger but don't care about subscribing to the result with the hook, you can use the `selectFromResult` option to limit the properties that the hook cares about.
129129
130130
Passing a completely empty object will prevent the hook from causing a re-render at all, e.g.
131+
131132
```ts
132133
selectFromResult: () => ({})
133134
```
135+
134136
:::
135137
136138
- **Returns**: a tuple containing:

docs/api/rtk-query/created-api/overview.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,34 @@ const api = createApi({
2525
endpoints: (builder) => ({
2626
// ...
2727
}),
28-
});
28+
})
2929

3030
type Api = {
3131
// Redux integration
32-
reducerPath: string;
33-
reducer: Reducer;
34-
middleware: Middleware;
32+
reducerPath: string
33+
reducer: Reducer
34+
middleware: Middleware
3535

3636
// Endpoint interactions
37-
endpoints: Record<string, EndpointDefinition>;
37+
endpoints: Record<string, EndpointDefinition>
3838

3939
// Code splitting and generation
40-
injectEndpoints: (options: InjectEndpointsOptions) => UpdatedApi;
41-
enhanceEndpoints: (options: EnhanceEndpointsOptions) => UpdatedApi;
40+
injectEndpoints: (options: InjectEndpointsOptions) => UpdatedApi
41+
enhanceEndpoints: (options: EnhanceEndpointsOptions) => UpdatedApi
4242

4343
// Cache management utilities
4444
utils: {
45-
updateQueryResult: UpdateQueryResultThunk;
46-
patchQueryResult: PatchQueryResultThunk;
47-
prefetch: PrefetchThunk;
48-
};
45+
updateQueryResult: UpdateQueryResultThunk
46+
patchQueryResult: PatchQueryResultThunk
47+
prefetch: PrefetchThunk
48+
}
4949

5050
// Internal actions
51-
internalActions: InternalActions;
51+
internalActions: InternalActions
5252

5353
// React hooks (if applicable)
54-
[key in GeneratedReactHooks]: GeneratedReactHooks[key];
55-
};
54+
[key in GeneratedReactHooks]: GeneratedReactHooks[key]
55+
}
5656
```
5757
5858
## Redux Integration
@@ -102,7 +102,7 @@ The core RTK Query `createApi` method is UI-agnostic, in the same way that the R
102102
However, RTK Query also provides the ability to auto-generate React hooks for each of your endpoints. Since this specifically depends on React itself, RTK Query provides an alternate entry point that exposes a customized version of `createApi` that includes that functionality:
103103
104104
```js
105-
import { createApi } from '@rtk-incubator/rtk-query/react';
105+
import { createApi } from '@reduxjs/toolkit/query/react'
106106
```
107107

108108
If you have used the React-specific version of `createApi`, the generated `Api` slice structure will also contain a set of React hooks. These endpoint hooks are available as `api.endpoints[endpointName].useQuery` or `api.endpoints[endpointName].useMutation`, matching how you defined that endpoint.
@@ -113,12 +113,12 @@ For example, if you had endpoints for `getPosts` and `updatePost`, these options
113113

114114
```ts title="Generated React Hook names"
115115
// Hooks attached to the endpoint definition
116-
const { data } = api.endpoints.getPosts.useQuery();
117-
const { data } = api.endpoints.updatePost.useMutation();
116+
const { data } = api.endpoints.getPosts.useQuery()
117+
const { data } = api.endpoints.updatePost.useMutation()
118118

119119
// Same hooks, but given unique names and attached to the API slice object
120-
const { data } = api.useGetPostsQuery();
121-
const [updatePost] = api.useUpdatePostMutation();
120+
const { data } = api.useGetPostsQuery()
121+
const [updatePost] = api.useUpdatePostMutation()
122122
```
123123

124124
The React-specific version of `createApi` also generates a `usePrefetch` hook, attached to the `Api` object, which can be used to initiate fetching data ahead of time.

docs/api/rtk-query/fetchBaseQuery.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It takes all standard options from fetch's [`RequestInit`](https://developer.moz
1919
- Allows you to inject headers on every request. You can specify headers at the endpoint level, but you'll typically want to set common headers like `authorization` here. As a convience mechanism, the second argument allows you to use `getState` to access your redux store in the event you store information you'll need there such as an auth token.
2020

2121
- ```ts title="prepareHeaders signature"
22-
(headers: Headers, api: { getState: () => unknown }) => Headers;
22+
;(headers: Headers, api: { getState: () => unknown }) => Headers
2323
```
2424

2525
- `fetchFn` _(optional)_
@@ -60,7 +60,7 @@ export const pokemonApi = createApi({
6060
}),
6161
}),
6262
}),
63-
});
63+
})
6464
```
6565

6666
### Setting default headers on requests
@@ -71,16 +71,16 @@ The most common use case for `prepareHeaders` would be to automatically include
7171
const baseQuery = fetchBaseQuery({
7272
baseUrl,
7373
prepareHeaders: (headers, { getState }) => {
74-
const token = (getState() as RootState).auth.token;
74+
const token = (getState() as RootState).auth.token
7575
7676
// If we have a token set in state, let's assume that we should be passing it.
7777
if (token) {
78-
headers.set('authorization', `Bearer ${token}`);
78+
headers.set('authorization', `Bearer ${token}`)
7979
}
8080
81-
return headers;
81+
return headers
8282
},
83-
});
83+
})
8484
```
8585

8686
### Individual query options
@@ -94,14 +94,15 @@ There is more behavior that you can define on a per-request basis that extends t
9494

9595
```ts title="endpoint request options"
9696
interface FetchArgs extends RequestInit {
97-
url: string;
98-
params?: Record<string, any>;
99-
body?: any;
100-
responseHandler?: 'json' | 'text' | ((response: Response) => Promise<any>);
101-
validateStatus?: (response: Response, body: any) => boolean;
97+
url: string
98+
params?: Record<string, any>
99+
body?: any
100+
responseHandler?: 'json' | 'text' | ((response: Response) => Promise<any>)
101+
validateStatus?: (response: Response, body: any) => boolean
102102
}
103103
104-
const defaultValidateStatus = (response: Response) => response.status >= 200 && response.status <= 299;
104+
const defaultValidateStatus = (response: Response) =>
105+
response.status >= 200 && response.status <= 299
105106
```
106107

107108
### Setting the body
@@ -168,7 +169,7 @@ export const customApi = createApi({
168169
}),
169170
}),
170171
}),
171-
});
172+
})
172173
```
173174

174175
:::note Note about responses that return an undefined body
@@ -186,9 +187,10 @@ export const customApi = createApi({
186187
getUsers: builder.query({
187188
query: () => ({
188189
url: `users`,
189-
validateStatus: (response, result) => response.status === 200 && !result.isError, // Our tricky API always returns a 200, but sets an `isError` property when there is an error.
190+
validateStatus: (response, result) =>
191+
response.status === 200 && !result.isError, // Our tricky API always returns a 200, but sets an `isError` property when there is an error.
190192
}),
191193
}),
192194
}),
193-
});
195+
})
194196
```

0 commit comments

Comments
 (0)