跳至内容

useLazyQuery

扩展 useQuery

附加返回值

  • load(document?, variables?, options?): 用于启动查询的函数。如果这是第一次调用查询,则返回 Promise<Result>,否则返回 false

    示例

    js
    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
      }
    }