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.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useExternal.jsonDynamically 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 |