1
1
# Examples
2
2
3
- ### Import Map
3
+ ### CDN + ESM
4
4
5
- Using ` tts-react ` with ESM from a CDN and [ import maps] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap ) :
5
+ Using ` tts-react ` with ESM from a CDN:
6
+
7
+ ``` html
8
+ <!doctype html>
9
+ <html lang =" en" >
10
+ <head >
11
+ <meta charset =" UTF-8" />
12
+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
13
+ <title >ESM + CDN</title >
14
+ </head >
15
+ <body >
16
+ <script type =" module" >
17
+ import { createElement } from ' https://esm.sh/react@rc/?dev'
18
+ import { createRoot } from ' https://esm.sh/react-dom@rc/client?dev'
19
+ import { TextToSpeech } from ' https://esm.sh/tts-react@next?deps=react@rc&dev'
20
+
21
+ createRoot (document .body ).render (
22
+ createElement (TextToSpeech, { markTextAsSpoken: true }, ' Hello from tts-react.' )
23
+ )
24
+ </script >
25
+ </body >
26
+ </html >
27
+ ```
28
+
29
+ #### ` htm `
30
+
31
+ Use [ ` htm ` ] ( https://github.com/developit/htm ) for JSX-like syntax:
32
+
33
+ ``` html
34
+ <!doctype html>
35
+ <html lang =" en" >
36
+ <head >
37
+ <meta charset =" UTF-8" />
38
+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
39
+ <title >ESM + CDN + htm</title >
40
+ </head >
41
+ <body >
42
+ <script type =" module" >
43
+ import { createElement } from ' https://esm.sh/react@rc/?dev'
44
+ import { createRoot } from ' https://esm.sh/react-dom@rc/client?dev'
45
+ import { TextToSpeech } from ' https://esm.sh/tts-react@next?deps=react@rc&dev'
46
+ import htm from ' https://esm.sh/htm'
47
+
48
+ const html = htm .bind (createElement)
49
+
50
+ createRoot (document .body ).render (
51
+ html `
52
+ <${ TextToSpeech} markTextAsSpoken>
53
+ <p >Hello from tts-react.</p >
54
+ </${ TextToSpeech} >
55
+ `
56
+ )
57
+ </script >
58
+ </body >
59
+ </html >
60
+ ```
61
+
62
+ #### Import Map
63
+
64
+ You can also use an [ import map] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap ) if you prefer bare specifiers in your import statements:
6
65
7
66
``` html
8
67
<!doctype html>
@@ -13,23 +72,30 @@ Using `tts-react` with ESM from a CDN and [import maps](https://developer.mozill
13
72
<script type =" importmap" >
14
73
{
15
74
" imports" : {
16
- " react" : " https://esm.sh/react@rc" ,
17
- " react-dom/" : " https://esm.sh/react-dom@rc/" ,
18
- " react/jsx-runtime " : " https://esm.sh/react@rc/jsx-runtime " ,
19
- " tts-react " : " https://esm.sh/tts-react@next "
75
+ " react" : " https://esm.sh/react@rc/?dev " ,
76
+ " react-dom/client " : " https://esm.sh/react-dom@rc/client?dev " ,
77
+ " tts-react " : " https://esm.sh/tts- react@next?deps=react@rc&dev " ,
78
+ " htm " : " https://esm.sh/htm "
20
79
}
21
80
}
22
81
</script >
23
- <title >ESM / CDN / Import Map</title >
82
+ <title >ESM + CDN + Import Map + htm </title >
24
83
</head >
25
84
<body >
26
85
<script type =" module" >
27
86
import { createElement } from ' react'
28
87
import { createRoot } from ' react-dom/client'
29
88
import { TextToSpeech } from ' tts-react'
89
+ import htm from ' htm'
90
+
91
+ const html = htm .bind (createElement)
30
92
31
93
createRoot (document .body ).render (
32
- createElement (TextToSpeech, { markTextAsSpoken: true }, ' Hello from tts-react.' )
94
+ html `
95
+ <${ TextToSpeech} markTextAsSpoken>
96
+ <p >Hello from tts-react.</p >
97
+ </${ TextToSpeech} >
98
+ `
33
99
)
34
100
</script >
35
101
</body >
0 commit comments