shadcn-ahooks

useExternal

Dynamically load JS or CSS, useExternal can ensure that the resource are globally unique.

Overview

Dynamically load JS or CSS, useExternal can ensure that the resource are globally unique.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.json

Dynamically load JS or CSS, useExternal can ensure that the resource are globally unique.

Example

Basic Usage

Load CSS

API

const status = useExternal(path: string, options?: Options);

Result

| Params | Description | Type | | | -- | -- | | status | The progress of loading the external resources, support unset, loading, ready, error | string |

Params

| Params | Description | Type | Default | | | ---- | | type | The type of external resources which need to load, support js/css, if no type, it will deduced according to path | string | - | | js | Attributes supported by script | HTMLScriptElement | - | | css | Attributes supported by link | HTMLStyleElement | - | | keepWhenUnused | Allow resources to remain after they have lost their references | boolean | false |

On this page