-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Update react-query depency to require at least v5.83 #10838
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 6 commits
2064847
fa92912
7fa11ed
045a823
9c821ba
1d615df
e124713
b56aca9
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 |
|---|---|---|
|
|
@@ -1174,6 +1174,43 @@ const ProductList = () => ( | |
| ) | ||
| ``` | ||
|
|
||
| ## Enabling Data Fetching Conditionally | ||
|
|
||
| You might want to allow data to be fetched only when at least some filters have been set. You can leverage TanStack react-query `enabled` option for that. It accepts a function that receives the query as its only parameter. As react-admin always format the `queryKey` as `[ResourceName, DataProviderMethod, DataProviderParams]`, you can check that there is at least a filter in this function: | ||
|
|
||
| {% raw %} | ||
| ```tsx | ||
| export const PostList = () => ( | ||
| <List | ||
| filters={postFilter} | ||
| queryOptions={{ | ||
| enabled: query => { | ||
| const listParams = query.queryKey[2] as GetListParams; | ||
| return listParams.filter.q?.length > 2; | ||
| } | ||
| }} | ||
| > | ||
| <WithListContext | ||
| render={context => | ||
| context.filterValues.q == null || | ||
| context.filterValues.q === '' ? ( | ||
|
||
| <CardContentInner> | ||
| Type a search term to fetch data | ||
| </CardContentInner> | ||
| ) : ( | ||
| <Datagrid> | ||
| {/* your fields */} | ||
| </Datagrid> | ||
| ) | ||
| } | ||
| /> | ||
| </List> | ||
| ) | ||
| ``` | ||
| {% endraw %} | ||
|
|
||
| **Note**: Notice we display some custom UI when there is no filter. This is because otherwise, users would see the loading UI as Tanstack Query will set the `isPending` property of the underlying query to `true` if the query isn't enabled. | ||
|
|
||
| ## Accessing Extra Response Data | ||
|
|
||
| If `dataProvider.getList()` returns additional metadata in the response under the `meta` key, you can access it in the list view using the `meta` property of the `ListContext`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,8 +57,7 @@ | |
| "react-router-dom": "^6.28.1 || ^7.1.1" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/react-query": "^5.21.7", | ||
| "clsx": "^2.1.1", | ||
|
Member
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. 👍 good catch |
||
| "@tanstack/react-query": "^5.83.0", | ||
| "date-fns": "^3.6.0", | ||
| "eventemitter3": "^5.0.1", | ||
| "inflection": "^3.0.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,7 @@ export const useGetList = < | |
| } | ||
| : result, | ||
| [result] | ||
| ) as UseQueryResult<RecordType[], Error> & { | ||
| ) as unknown as UseQueryResult<RecordType[], Error> & { | ||
|
Member
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. Question: Why do we only need to do that when calling
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. Because
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. For the record, I'd love to change that in v6 |
||
| total?: number; | ||
| pageInfo?: { | ||
| hasNextPage?: boolean; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,7 +248,6 @@ export type UseInfiniteGetListOptions< | |
| GetInfiniteListResult<RecordType>, | ||
| ErrorType, | ||
| InfiniteData<GetInfiniteListResult<RecordType>>, | ||
| GetInfiniteListResult<RecordType>, | ||
|
Member
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. does that mean that the type of
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. No I believe we used it incorrectly before but it wasn't detected until this update
Member
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 think it's due to TanStack/query#8956. It doesn't seem to be a breaking change. |
||
| QueryKey, | ||
| number | ||
| >, | ||
|
|
||
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'm not sure about where to put this documentation as it's actually
useGetListthat we configure.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 it's fine here 👍