feat(useLazyQuery): load returns Promise, fix #1486

This commit is contained in:
Guillaume Chau
2023-09-12 16:52:13 +02:00
parent daffd75db2
commit 96cc4fe78a
8 changed files with 200 additions and 30 deletions
+11 -2
View File
@@ -4,14 +4,23 @@ Extends [useQuery](./use-query.md)
## Additional Return
- `load(document?, variables?, options?)`: function to start querying. Returns `true` if it is the first time the query is called, `false` otherwise.
- `load(document?, variables?, options?)`: function to start querying. Returns `Promise<Result>` if it is the first time the query is called, `false` otherwise.
Example:
```js
const { load, refetch } = useLazyQuery(query, variables, options)
function fetchMyData () {
function fetchOrRefetch () {
load() || refetch()
}
function waitForLoad () {
try {
const result = await load()
// do something with result
} catch (error) {
// handle error
}
}
```