fn
useStyleTag
v0.0.15testeddemoInject a reactive `<style>` tag into the document `<head>`. The CSS is a writable ref — assigning to it updates the live stylesheet. Multiple instances sharing an `id` reuse a single element via reference counting, and everything is SSR-safe.
Examples
ts
const { css, isLoaded } = useStyleTag('body { color: red }');
css.value = 'body { color: blue }';ts
// Manual control
const { load, unload } = useStyleTag('.a { color: red }', { manual: true });
load();
unload();Demo
Loading demo…
Signature
ts
export function useStyleTag(
css: MaybeRefOrGetter<string>,
options: UseStyleTagOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
css | MaybeRefOrGetter<string> | Reactive CSS source for the tag |
options? | UseStyleTagOptions | Options |
Returns
UseStyleTagReturn`{ id, css, load, unload, isLoaded }`