Skip to content

Commit 405cd43

Browse files
committed
- Remove copy of defaultSerializeQueryArgs,
replace with written explanation of behaviour
1 parent f2a02c3 commit 405cd43

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

docs/api/rtk-query/createApi.mdx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,7 @@ export const { endpoints, reducerPath, reducer, middleware } = api
250250

251251
[summary](docblock://query/createApi.ts?token=CreateApiOptions.serializeQueryArgs)
252252

253-
Defaults to:
254-
255-
```ts no-transpile
256-
export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
257-
endpointName,
258-
queryArgs,
259-
}) => {
260-
// Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 })
261-
return `${endpointName}(${JSON.stringify(queryArgs, (key, value) =>
262-
isPlainObject(value)
263-
? Object.keys(value)
264-
.sort()
265-
.reduce<any>((acc, key) => {
266-
acc[key] = (value as any)[key]
267-
return acc
268-
}, {})
269-
: value
270-
)})`
271-
}
272-
```
253+
By default, this function will take the query arguments, sort object keys where applicable, stringify the result, and concatenate it with the endpoint name. This creates a cache key based on the combination of arguments + endpoint name (ignoring object key order), such that calling any given endpoint with the same arguments will result in the same cache key.
273254

274255
### `keepUnusedDataFor`
275256

0 commit comments

Comments
 (0)