Skip to content

Commit e87d156

Browse files
committed
chore: remove createStore option
having the option to customize the internal store sound nice, but the problem is that the store holds Query instances, not data. So, the setter is only called once, not on every data update. This makes it relatively useless - every time we thought we could leverage createStore, it fell short of our requirements because of this. The better way is usually to subscribe to the QueryCache directly
1 parent 0e3f15b commit e87d156

File tree

4 files changed

+1
-34
lines changed

4 files changed

+1
-34
lines changed

docs/react/guides/migrating-to-v5.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,4 @@ Note that the infinite list must be bi-directional, which requires both `getNext
443443

444444
See the [Typescript Docs](../typescript#typing-query-options) for more details.
445445

446-
### CreateStore
447-
448-
We are now exposing a way to customize how queries are stored internally. Per default, a `Map` is used but, with the new `createStore` function, you can now use any data structure you want.
449-
450-
```ts
451-
const queryClient = new QueryClient({
452-
queryCache: new QueryCache({
453-
createStore: () => new Map()
454-
}),
455-
})
456-
```
457-
458446
[//]: # 'NewFeatures'

docs/react/reference/QueryCache.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ Its available methods are:
4343
- `onSettled?:` (data: unknown | undefined, error: unknown | null, query: Query) => void
4444
- Optional
4545
- This function will be called if some query is settled (either successful or errored).
46-
- `createStore?: () => QueryStore`
47-
- Optional
48-
- This function will be called to create the store that will be used to store the queries. By default, a `Map` is used.
4946

5047
## Global callbacks
5148

packages/query-core/src/queryCache.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ interface QueryCacheConfig {
2727
error: DefaultError | null,
2828
query: Query<unknown, unknown, unknown>,
2929
) => void
30-
createStore?: () => QueryStore
3130
}
3231

3332
interface NotifyEventQueryAdded extends NotifyEvent {
@@ -95,7 +94,7 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
9594

9695
constructor(public config: QueryCacheConfig = {}) {
9796
super()
98-
this.#queries = config.createStore?.() ?? new Map<string, Query>()
97+
this.#queries = new Map<string, Query>()
9998
}
10099

101100
build<TQueryFnData, TError, TData, TQueryKey extends QueryKey>(

packages/query-core/src/tests/queryCache.test.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,23 +329,6 @@ describe('queryCache', () => {
329329
})
330330
})
331331

332-
describe('QueryCacheConfig.createStore', () => {
333-
test('should call createStore', async () => {
334-
const createStore = vi.fn().mockImplementation(() => new Map())
335-
new QueryCache({ createStore })
336-
expect(createStore).toHaveBeenCalledWith()
337-
})
338-
339-
test('should use created store', async () => {
340-
const store = new Map()
341-
const spy = vi.spyOn(store, 'get')
342-
343-
new QueryCache({ createStore: () => store }).get('key')
344-
345-
expect(spy).toHaveBeenCalledTimes(1)
346-
})
347-
})
348-
349332
describe('QueryCache.add', () => {
350333
test('should not try to add a query already added to the cache', async () => {
351334
const key = queryKey()

0 commit comments

Comments
 (0)