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

ParamsDescriptionType
statusThe progress of loading the external resources, support unset, loading, ready, errorstring

Params

ParamsDescriptionTypeDefault
pathThe url of the external resourcesstring-

Options

ParamsDescriptionTypeDefault
typeThe type of external resources which need to load, support js/css, if no type, it will deduced according to pathstring-
jsAttributes supported by scriptHTMLScriptElement-
cssAttributes supported by linkHTMLStyleElement-
keepWhenUnusedAllow resources to remain after they have lost their referencesbooleanfalse

On this page