feat(useLazyQuery): load returns Promise, fix #1486
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user