If you have any project questions, concerns, or contribution ideas, join our #pwa Slack channel. Find out how to create an account by visiting Community Resources

useQuery

Functions

useQuery(query)Array.<Object>

A React Hook that provides access to query results data and an API object for running the query and managing a query result state object.

Typedefs

API : Object

The API for managing the query. Use this API to run queries and get the resulting state values and query data.

In addition to the runQuery() function, this object also contains the API methods from the useQueryResult hook.

useQuery(query) ⇒ Array.<Object>

A React Hook that provides access to query results data and an API object for running the query and managing a query result state object.

Kind: global function
Returns: Array.<Object> - An array with two entries containing the following content: [QueryResultState, API]

Param Type Description
query DocumentNode A GraphQL document containing a query to send to the server. See graphql-tag

API : Object

The API for managing the query. Use this API to run queries and get the resulting state values and query data.

In addition to the runQuery() function, this object also contains the API methods from the useQueryResult hook.

Kind: global typedef

API.runQuery(query)

A callback function that performs a query either as an effect or in response to user interaction.

Kind: static method of API

Param Type Description
query DocumentNode A GraphQL document

For implementation details View Source.

Examples

Send a product search query to the server and get back the query result state object.

import PRODUCT_SEARCH from '../queries/productSearch.graphql';

const [queryResult, queryApi] = useQuery(PRODUCT_SEARCH);

const { data, error, loading } = queryResult;