You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under the hood `createScript` makes use of the `createResource` Solid API when loading the desired script at the specified `src`. As such, the result of `createScript` is a `Resource<Event>` object that allows you to inspect when the script has finished loading or returned an error via `script.loading` and `script.error` respectively.
40
+
The three arguments:
29
41
30
-
When using `createScript`, here are some points to be aware of:
42
+
- `src`: the script source to download
43
+
- `attributes`: any `<script>` specific attributes to apply
31
44
32
-
- The created `<script>` tag will be appeneded to `<head>`.
33
-
- The created `<script>` tag will not be removed from the DOM when a component that uses this hook unmounts. (i.e. we do not make use of `onCleanup` to remove the `<script>` from `<head>`).
34
-
- The hook will ensure no duplicate `<script>` tags referencing the same `src` will be created. Moreover, when multiple components reference the same `src`, they will all point to the same shared resource ensuring consistency within the reactive graph.
45
+
It is useful for:
35
46
36
-
### Full Example
47
+
- Conditionally rendering based on script load status
<Matchwhen={script.error}>Failed to load script: {script.error.message}</Match>
62
+
<Matchwhen={script.error}>Failedtoload</Match>
63
+
<Matchwhen={script()}>Scriptisready!</Match>
49
64
</Switch>
50
-
);
65
+
)
51
66
}
67
+
52
68
```
53
69
54
-
### Feedback
70
+
> ⚠️ The `<script>` that is downloaded with `createScript` will be appended to `<head>`. This API currently does not support specifying a mount target for the `<script>` tag.
71
+
72
+
---
73
+
74
+
### `loadScript` (Imperative API)
75
+
76
+
Utility function that returns a `Promise<HTMLScriptElement>`.
0 commit comments