# use-suspense-query

> ## How to use

Latest version **1.0.1** (published 2020-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-suspense-query
pnpm add use-suspense-query
yarn add use-suspense-query
bun add use-suspense-query
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-05-30 |
| First published | 2020-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 51.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Przemyslaw Nowak |
| Maintainers | fasosnql |

## Links

- npm: https://www.npmjs.com/package/use-suspense-query
- npm.io page: https://npm.io/package/use-suspense-query

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^8.1.0
- [ramda](https://npm.io/package/ramda.md) ^0.27.0
- [@types/react](https://npm.io/package/@types/react.md) ^16.9.35

## Recent versions

- 1.0.1 (latest) — 2020-05-30
- 1.0.0 — 2020-05-30

## README

# Apollo Client - useSuspenseQuery

## How to use

```shell script
$ npm install use-suspense-query
```

To use hook in your app you have to provide apollo client via. `SuspenseQueryProvider` i.e:
```jsx
import { SuspenseQueryProvider } from 'use-suspense-query';

const apolloClient = new ApolloClient({
  link,
  cache
});

export function App() {
  return (
    <SuspenseQueryProvider client={apolloClient}>
        <div>
          <OtherComponent />
        </div>
    </SuspenseQueryProvider>
  );
}
```

Now you're able to use hook in your app. Example usage:
```jsx
import { qgl } from '@apollo/client';
import { useSuspenseQuery } from 'use-suspense-query';

const myQuery = gql`
  query getSth($id: ID!) {
    data(id: $id) {
      sth
    }
  }
`

function DataComponent() {
  const data = useSuspenseQuery(myQuery, {
    variables: {
      id: '1234'
    }
  });

  return (<div>display {data} here</div>);
}

export function App() {
  return (
    <Suspense fallback={...YourFallbackComponent}>
      <DataComponent />
    </Suspense>
  )
}
```

### Hook API
```jsx
useSuspenseQuery(query: GraphqlQuery, options: Options): Response of ApolloClient.query()
```

### 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 |

---
_Source: https://npm.io/package/use-suspense-query · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
