Skip to content

Commit

Permalink
fix(useQuery): Add function type for definition prop
Browse files Browse the repository at this point in the history
To use the enabled option, the definition is passed in the form of a general function. I've adapted the typing to this practice. This allows me to display the warning also for definition passed with a function
  • Loading branch information
cballevre committed May 23, 2024
1 parent df1dc7f commit 21fca5c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api/cozy-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
4 changes: 2 additions & 2 deletions packages/cozy-client/src/hooks/useQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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.'
)
Expand Down
4 changes: 2 additions & 2 deletions packages/cozy-client/types/hooks/useQuery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 21fca5c

Please sign in to comment.