Skip to content
GaudiGaudi Design System home

Search documentation

Search every page, heading and paragraph.

useScript

Load an explicitly configured script with shared status and ownership.

HooksEnvironment@gaudi/design-system/hooks/environment/use-scriptView in StorybookSource

Callers using the same resolved URL share one script. A null source or disabled hook stays idle. No URL is built in, and Storybook uses a local inert fixture. The copied example includes the public file location and contents to create in your app.

Usage

import { useScript } from '@gaudi/design-system/hooks';
const status = useScript('/scripts/local-preview.js', { enabled: previewOpen });

Examples

Playground

Storybook

API

3 options
1 return value

Accessibility

Provide text for loading/error states and an alternative when an integration is unavailable.

Notes

  • Removing a script tag cannot undo code it already ran. Prefer retaining shared libraries.
  • Pre-existing scripts are never removed. Mark known external script state with data-gaudi-script-status="ready" or wait for its load/error event.
  • Failed retained scripts stay error; use a new URL or removeOnUnmount to release the failed entry before retrying.