Files
apollo/packages/docs/src/api/use-lazy-query.md
T
2023-09-12 16:52:13 +02:00

581 B

useLazyQuery

Extends useQuery

Additional Return

  • load(document?, variables?, options?): function to start querying. Returns Promise<Result> if it is the first time the query is called, false otherwise.

    Example:

    const { load, refetch } = useLazyQuery(query, variables, options)
    
    function fetchOrRefetch () {
      load() || refetch()
    }
    
    function waitForLoad () {
      try {
        const result = await load()
        // do something with result
      } catch (error) {
        // handle error
      }
    }