# @teamleader/react-hooks-api

> React hooks for the Teamleader API

Latest version **0.0.4** (published 2019-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @teamleader/react-hooks-api
pnpm add @teamleader/react-hooks-api
yarn add @teamleader/react-hooks-api
bun add @teamleader/react-hooks-api
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-07-11 |
| First published | 2019-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 148.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | arnaudweyts, driesd, duivvv, instak, kemosabert, lennert_blommaert, mikeverf, nickwaelkens, stephenv29, teamleader-guild, timdegroote, wielo |
| Keywords | react, react-hooks, teamleader, teamleader-api |

## Links

- npm: https://www.npmjs.com/package/@teamleader/react-hooks-api
- Repository: https://github.com/teamleadercrm/react-hooks-api
- Homepage: https://github.com/teamleadercrm/react-hooks-api#readme
- Issues: https://github.com/teamleadercrm/react-hooks-api/issues
- npm.io page: https://npm.io/package/@teamleader/react-hooks-api

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2019-07-11
- 0.1.0-rc14 (next) — 2020-04-28
- 0.1.0-rc13 — 2020-04-23
- 0.1.0-rc12 — 2020-03-04
- 0.1.0-rc11 — 2020-01-29
- 0.1.0-rc10 — 2020-01-29
- 0.1.0-rc9 — 2020-01-28
- 0.1.0-rc8 — 2020-01-23
- 0.1.0-rc7 — 2020-01-13
- 0.1.0-rc6 — 2020-01-09
- 0.1.0-rc5 — 2020-01-07
- 0.1.0-rc4 — 2020-01-07
- 0.1.0-rc3 — 2019-12-02
- 0.1.0-rc2 — 2019-12-02
- 0.1.0-rc1 — 2019-11-29
- … 3 more at https://npm.io/package/@teamleader/react-hooks-api/versions

## README

# 🎣 @teamleader/react-hooks-api

React hooks for the Teamleader API

## Installation

```sh
yarn add @teamleader/react-hooks-api
```

or

```sh
npm install --save @teamleader/react-hooks-api
```

## Getting started

#### Wrap your root inside the `Provider` component and provide an initialized [@teamleader/api](https://github.com/teamleadercrm/sdk-js) config.

```jsx
import React from 'react';
import { Provider } from '@teamleader/react-hooks-api';
import { API as initializeAPI } from '@teamleader/api';

import App from '../App';

const API = initializeAPI({...})

const Root = () => {
  return (
    <Provider api={API}>
      <App />
    </Provider>
  );
}

export default Root;
```

#### You can now start using `useQuery` in your components to fetch data.

```jsx
import React from 'react';
import { useQuery } from '@teamleader/react-hooks-api';

const QUERY = () => ({
  domain: 'projects',
  action: 'list',
});

const Component = () => {
  const { loading, error, data } = useQuery(QUERY);

  if (loading || !data) {
    return 'Loading...';
  }

  if (error) {
    return 'Error';
  }

  if (data) {
    return data;
  }

  // default
  return null;
};

export default Root;
```

## API

### `useQuery`

Signature: `(query: Query, variables: Variables, options: Options) => QueryValues`

[Query](#query)

[Variables](#variables)

[QueryValues](#queryvalues)

[Options](#options)

### `Query`

A function that returns an object. This function can be defined with variables when you need to update it dynamically.

### `Variables`

The variables to be passed to the [Query](#query). When updated, it will re-run the query.

### `QueryValues`

```
loading: Boolean
error?: Error
data?: Response
```

### `Options`

```js
{
  ignoreCache: boolean; // default: false
}
```

---
_Source: https://npm.io/package/@teamleader/react-hooks-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
