# @charlietango/use-script

> Load an external third party script

Latest version **2.3.0** (published 2022-04-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @charlietango/use-script
pnpm add @charlietango/use-script
yarn add @charlietango/use-script
bun add @charlietango/use-script
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2022-04-14 |
| First published | 2019-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Maintainers | thebuilder, frederik_bosch |
| Keywords | react, hooks |

## Links

- npm: https://www.npmjs.com/package/@charlietango/use-script
- Repository: https://github.com/charlie-tango/hooks
- Homepage: https://github.com/charlie-tango/hooks#readme
- Issues: https://github.com/charlie-tango/hooks/issues
- npm.io page: https://npm.io/package/@charlietango/use-script

## Dependencies (1)

- [@charlietango/use-client-hydrated](https://npm.io/package/@charlietango/use-client-hydrated.md) ^1.10.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

- 2.3.0 (latest) — 2022-04-14
- 2.2.0 — 2020-10-19
- 2.1.2 — 2020-09-23
- 2.1.1 — 2020-06-09
- 2.1.0 — 2019-11-25
- 2.0.2 — 2019-11-13
- 2.0.1 — 2019-09-25
- 2.0.0 — 2019-08-22
- 1.2.4 — 2019-06-28
- 1.2.3 — 2019-06-06
- 1.2.2 — 2019-04-30
- 1.2.1 — 2019-03-12
- 1.2.0 — 2019-03-08
- 0.1.7 — 2019-02-27
- 0.1.6 — 2019-02-27
- … 3 more at https://npm.io/package/@charlietango/use-script/versions

## README

# useScript

With `useScript` you can lazy-load external third party scripts, that your
components might depend on. It checks if the requested `url` already exists and reuses it, instead of creating a new load request.

> Checkout the [Storybook](https://ct-hooks.now.sh/?path=/story/usescript--readme) demo.

## Installation

```sh
yarn add @charlietango/use-script
```

## API

```js
const [ready, status] = useScript(url)
```

The hook returns an array, where the first value is a boolean indicating if the script is ready.
The second value is the current loading status, that will be one of the `ScriptStatus` enum values:

```ts
enum ScriptStatus {
  IDLE = 'idle',
  LOADING = 'loading',
  READY = 'loaded',
  ERROR = 'error',
}
```

## Example

```jsx
import React from 'react'
import useScript, { ScriptStatus } from '@charlietango/use-script'

const Component = () => {
  const [ready, status] = useScript('https://api.google.com/api.js')

  if (status === ScriptStatus.ERROR) {
    return <div>Failed to load Google API</div>
  }

  return <div>Google API Ready: {ready}</div>
}

export default Component
```

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