4
4
5
5
[ ![ NPM Version] ( https://img.shields.io/npm/v/@dschz/solid-create-script.svg?style=for-the-badge )] ( https://www.npmjs.com/package/@dschz/solid-create-script )
6
6
[ ![ Build Status] ( https://img.shields.io/github/actions/workflow/status/dsnchz/solid-create-script/ci.yaml?branch=main&logo=github&style=for-the-badge )] ( https://github.com/dsnchz/solid-create-script/actions/workflows/ci.yaml )
7
- [ ![ bun] ( https://img.shields.io/badge/maintained%20with-bun-cc00ff.svg?style=for-the-badge&logo=bun )] ( https://bun.sh/ )
7
+ [ ![ TypeScript] ( https://img.shields.io/badge/TypeScript-supported-blue?style=for-the-badge&logo=typescript )] ( https://www.typescriptlang.org/ )
8
+ [ ![ SSR Compatible] ( https://img.shields.io/badge/SSR-compatible-brightgreen?style=for-the-badge )] ( # )
8
9
9
10
# @dschz/solid-create-script
10
11
11
- > SolidJS hook to declaratively load external scripts, built on top of [ ` @dschz/load-script ` ] ( https://www.npmjs.com/package/@dschz/load-script ) .
12
+ > SolidJS hook to load external scripts -- built on top of [ ` @dschz/load-script ` ] ( https://www.npmjs.com/package/@dschz/load-script ) .
12
13
13
14
## ✅ Features
14
15
20
21
21
22
``` bash
22
23
npm install solid-js @dschz/load-script @dschz/solid-create-script
23
-
24
24
pnpm install solid-js @dschz/load-script @dschz/solid-create-script
25
-
26
25
yarn install solid-js @dschz/load-script @dschz/solid-create-script
27
-
28
26
bun install solid-js @dschz/load-script @dschz/solid-create-script
29
27
```
30
28
@@ -37,15 +35,15 @@ bun install solid-js @dschz/load-script @dschz/solid-create-script
37
35
38
36
### ` createScript(src, options?, container?) `
39
37
40
- Wraps ` loadScript ` in a ` createResource() ` to enable declarative async tracking inside SolidJS .
38
+ Loads an external script dynamically and returns a ` Resource<HTMLScriptElement> ` .
41
39
42
40
#### Parameters:
43
41
44
- - ` src ` _ (string) _ : the script source to download
45
- - ` options ` _ (LoadScriptOptions) _ : standard script attributes (e.g. ` async ` , ` type ` , ` nonce ` , etc.)
46
- - ` container ` _ (HTMLElement) _ : DOM node to append the script to (defaults to ` document.head ` )
47
-
48
- Returns a Solid ` Resource<HTMLScriptElement> ` .
42
+ | Name | Type | Description |
43
+ | ----------- | ------------------- | ----------------------------------------------------------------- |
44
+ | ` src ` | ` string ` | Script URL (required) |
45
+ | ` options ` | ` LoadScriptOptions ` | ` loadScript ` options (e.g. ` async ` , ` type ` ) |
46
+ | ` container ` | ` HTMLElement ` | HTML element to append ` <script /> ` to (default: ` document.head ` ) |
49
47
50
48
## 🧪 Example
51
49
@@ -70,7 +68,7 @@ const CustomComponent = () => {
70
68
71
69
- Scripts are cached by ` src ` unless ` innerHTML ` or ` textContent ` is used
72
70
- Scripts are not automatically removed on cleanup/unmount
73
- - Designed to be simple and safe to use inside SolidJS components
71
+ - Designed to be simple and safe to use inside SolidJS components (in SSR and non-SSR environments)
74
72
75
73
## 💬 Feedback & Contributions
76
74
0 commit comments