Skip to content

Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement.

Notifications You must be signed in to change notification settings

penx/use-async-query

Repository files navigation

useAsyncQuery

Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement.

Usage

npm i use-async-query

Example usage with Firestore

import firestore from '@firebase/firestore'
import { useQuery } from 'use-async-query'

import { Loading, Error, Results } from './components'

const myQuery = (variables) => firestore()
  .collection('myCollection')
  .where('example', '==', variables.example)
  .get()

const MyComponent = () => {
  const {loading, error, data} = useQuery(myQuery, { variables: { example: 'test' }})

  return <>
    {loading && <Loading />}
    {error && <Error error={error} />}
    {data && <Results data={data}>}
  </>
}

About

Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published