diff --git a/docs/api/cozy-client/README.md b/docs/api/cozy-client/README.md index 7e2d1f8c00..39ae3f65a9 100644 --- a/docs/api/cozy-client/README.md +++ b/docs/api/cozy-client/README.md @@ -894,7 +894,7 @@ Fetches a queryDefinition and returns the queryState | Name | Type | Description | | :------ | :------ | :------ | -| `queryDefinition` | [`QueryDefinition`](classes/QueryDefinition.md) | Definition created with Q() | +| `queryDefinition` | [`QueryDefinition`](classes/QueryDefinition.md) | () => [`QueryDefinition`](classes/QueryDefinition.md) | Definition created with Q() | | `options` | `QueryOptions` | Options created with Q() | *Returns* diff --git a/packages/cozy-client/src/hooks/useQuery.js b/packages/cozy-client/src/hooks/useQuery.js index db6f5c3b9e..7bff34c242 100644 --- a/packages/cozy-client/src/hooks/useQuery.js +++ b/packages/cozy-client/src/hooks/useQuery.js @@ -21,7 +21,7 @@ const generateFetchMoreQueryDefinition = queryResult => { /** * Fetches a queryDefinition and returns the queryState * - * @param {QueryDefinition} queryDefinition - Definition created with Q() + * @param {QueryDefinition|(() => QueryDefinition)} queryDefinition - Definition created with Q() * @param {import("../types").QueryOptions} options - Options created with Q() * @returns {import("../types").UseQueryReturnValue} */ @@ -51,7 +51,7 @@ const useQuery = (queryDefinition, options) => { const client = useClient() const queryState = useSelector(() => { - if (options.singleDocData === undefined && queryDefinition.id) { + if (options.singleDocData === undefined && definition?.id) { logger.warn( 'useQuery options.singleDocData will pass to true in a next version of cozy-client, please add it now to prevent any problem in the future.' ) diff --git a/packages/cozy-client/types/hooks/useQuery.d.ts b/packages/cozy-client/types/hooks/useQuery.d.ts index 0465270e1c..d05eae2c1b 100644 --- a/packages/cozy-client/types/hooks/useQuery.d.ts +++ b/packages/cozy-client/types/hooks/useQuery.d.ts @@ -3,9 +3,9 @@ export default useQuery; /** * Fetches a queryDefinition and returns the queryState * - * @param {QueryDefinition} queryDefinition - Definition created with Q() + * @param {QueryDefinition|(() => QueryDefinition)} queryDefinition - Definition created with Q() * @param {import("../types").QueryOptions} options - Options created with Q() * @returns {import("../types").UseQueryReturnValue} */ -declare function useQuery(queryDefinition: QueryDefinition, options: import("../types").QueryOptions): import("../types").UseQueryReturnValue; +declare function useQuery(queryDefinition: QueryDefinition | (() => QueryDefinition), options: import("../types").QueryOptions): import("../types").UseQueryReturnValue; import { QueryDefinition } from "../queries/dsl";