# react-google-picker-hook

> Google Drive API hook for React

Latest version **1.3.1** (published 2023-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-google-picker-hook
pnpm add react-google-picker-hook
yarn add react-google-picker-hook
bun add react-google-picker-hook
```

## 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.3.1 |
| Published | 2023-06-23 |
| First published | 2022-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 46 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Lukas Cizek |
| Maintainers | globus303 |
| Keywords | react, google drive, drive, google picker, google identity service for web |

## Links

- npm: https://www.npmjs.com/package/react-google-picker-hook
- Repository: https://github.com/GLObus303/react-google-picker-hook
- Homepage: https://github.com/GLObus303/react-google-picker-hook#readme
- Issues: https://github.com/GLObus303/react-google-picker-hook/issues
- npm.io page: https://npm.io/package/react-google-picker-hook

## Dependencies (1)

- [use-script](https://npm.io/package/use-script.md) ^3.0.0

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

- 1.3.1 (latest) — 2023-06-23
- 1.3.0 — 2023-06-23
- 1.2.3 — 2022-12-31
- 1.2.2 — 2022-12-31
- 1.2.1 — 2022-12-30
- 1.2.0 — 2022-12-30
- 1.1.0 — 2022-12-30
- 1.0.0 — 2022-12-30
- 0.0.0 — 2022-12-30

## README

# React Google Drive picker hook

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
<a href="https://www.npmjs.com/package/react-google-picker-hook">
<img alt="npm latest version" src="https://img.shields.io/npm/v/react-google-picker-hook">
</a>

<b>Google Drive API hook for React compatible with the newest Google auth API</b>

# Installation

[![module formats: cjs, and esm](https://img.shields.io/badge/module%20formats-cjs%2c%20esm-green.svg?style=flat)](https://www.npmjs.com/package/react-google-picker-hook?activeTab=explore)

## General

1. Add the `react-google-picker-hook` package

```bash
# yarn
yarn add react-google-picker-hook

## optional
yarn add --dev @types/google.picker
```

```bash
# npm
npm install react-google-picker-hook --save

## optional
npm install @types/google.picker --save-dev
```

2. Use the package

```ts
import { useGooglePicker } from 'react-google-picker-hook';

const [openPicker] = useGooglePicker(
  (data: GoogleDrivePickerData, token: string) => {
    console.log({ data, token });

    if (data?.action === GOOGLE_ACTION.PICKED) {
      // Handle file pick
    }
  },
  {
    googleAppId: 'googleAppId',
    googleAuthClientId: 'googleAuthClientId',
    googleAppKey: 'googleAppKey',
  },
);

// ...

return <button onClick={openPicker}>Upload!</button>;
```

## Handling errors (optional)

There are two separate error callback which can be used for error detection.

```ts
const [openPicker] = useGooglePicker(
  // ... base callback
  {
    onAuthFailed: (response: TokenResponse) => {
      console.log(response.error_description || response.details);

      // handle auth error
    },
    tokenClientConfig: {
      error_callback: ({ message, stack, type }: ErrorCallback) => {
        console.log({ message, stack, type });

        // handle client error
      },
    },
  },
);
```

## Extending the default config (optional)

### Two custom configs objects

- `tokenClientConfig` is spread to Google's `initTokenClient`
- `customPickerConfig` is used to override the minimal default config used for picker

```ts
const [openPicker] = useGooglePicker(
  // ... base callback
  {
    customPickerConfig: {
      // custom picker config
    },
    tokenClientConfig: {
      /* custom config for initTokenClient */
    },
  },
);
```

### Two config callback functions

- `appendCustomPickerConfig`
- `appendCustomViewConfig`

Both used to extend the builder pattern of `DocsView` and `PickerBuilder`

```ts
const [openPicker] = useGooglePicker(
  // ... base callback
  {
    appendCustomViewConfig: (view) => {
      // extend by calling any of the inner setters
      return view;
    },
    appendCustomPickerConfig: (picker) => picker.setSize(300, 300),
  },
);
```

---
_Source: https://npm.io/package/react-google-picker-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
