-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(queryClient): add setQueriesData utility #2204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7e7d2d3
e29ae76
37a3118
0e4a8c5
b260c6e
adbd81f
94986b4
0f2895a
82f81be
c42be83
9ce8af1
0321539
95bed80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,33 @@ export class QueryClient { | |
| .setData(updater, options) | ||
| } | ||
|
|
||
| setQueriesData<TData>( | ||
| queryKey: QueryKey, | ||
| updater: Updater<TData | undefined, TData>, | ||
| options?: SetDataOptions | ||
| ): [QueryKey, TData][] | ||
|
|
||
| setQueriesData<TData>( | ||
| filters: QueryFilters, | ||
|
Comment on lines
+132
to
+133
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't create an overload that accepts queryKey and filters, even though some other functions have this, because the |
||
| updater: Updater<TData | undefined, TData>, | ||
| options?: SetDataOptions | ||
| ): [QueryKey, TData][] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this is the best return type - wanted to provide a way to show which key actually had data set, as calling |
||
|
|
||
| setQueriesData<TData>( | ||
| queryKeyOrFilters: QueryKey | QueryFilters, | ||
| updater: Updater<TData | undefined, TData>, | ||
| options?: SetDataOptions | ||
| ): [QueryKey, TData][] { | ||
| return notifyManager.batch(() => | ||
| this.getQueryCache() | ||
| .findAll(queryKeyOrFilters) | ||
| .map(({ queryKey }) => [ | ||
| queryKey, | ||
| this.setQueryData<TData>(queryKey, updater, options), | ||
| ]) | ||
| ) | ||
| } | ||
|
|
||
| getQueryState<TData = unknown, TError = undefined>( | ||
| queryKey: QueryKey, | ||
| filters?: QueryFilters | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we are not creating queries like with
setQueryData, because we only update matching keys, wouldupdateQueriesorupdateQueriesDatabe a better name?this was also mentioned by @tannerlinsley here: #135 (comment)
but I don't think it made it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current name is fine as long as people realize that it will not create queries.