Back to Hooks

useExternal

packages/hooks/src/useExternal/index.en-US.md

3.9.71.9 KB
Original Source

useExternal

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

Example

Basic Usage

<code src="./demo/demo1.tsx" />

Load CSS

<code src="./demo/demo2.tsx" />

API

typescript
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