Apollo Client - useSuspenseQuery
How to use
$ npm install use-suspense-query
To use hook in your app you have to provide apollo client via. SuspenseQueryProvider
i.e:
import SuspenseQueryProvider from 'use-suspense-query'; const apolloClient = link cache; { return <SuspenseQueryProvider => <div> <OtherComponent /> </div> </SuspenseQueryProvider> ;}
Now you're able to use hook in your app. Example usage:
import qgl from '@apollo/client';import useSuspenseQuery from 'use-suspense-query'; const myQuery = gql` query getSth($id: ID!) { data(id: $id) { sth } }` { const data = ; return <div>display data here</div>;} { return <Suspense => <DataComponent /> </Suspense> }
Hook API
: Response of ApolloClient
Hook Options
Option | Description | Type |
---|---|---|
variables | query variables | Object |
fetchPolicy | fetch policy option passing to ApolloClient fetchPolicy field | String |
uniqueKey | In default that key is generated based on variables and query, but to be sure that your request is totally unique, you should pass this field with some unique value - recommended to add uniqueKey! | String |