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
Copy file name to clipboardExpand all lines: docs/components/api.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ Once all the metadata has been collected, all the decorators are removed from th
25
25
-[@Listen()](./events.md#listen-decorator) listens for DOM events
26
26
-[@AttrDeserialize()](./serialization-deserialization.md#the-attrdeserialize-decorator-attrdeserialize) declares a hook to translate a component's attribute string to its JS property
27
27
-[@PropSerialize()](./serialization-deserialization.md#the-propserialize-decorator-propserialize) declares a hook that translates a component's JS property to its attribute string
28
+
-[@AttachInternals()](./attach-internals.md) attaches ElementInternals to a component
28
29
29
30
30
31
## Lifecycle hooks
@@ -119,9 +120,11 @@ The following primitives can be imported from the `@stencil/core` package and us
119
120
120
121
### [**h()**](./templating-and-jsx.md):
121
122
122
-
It's used within the `render()` to turn the JSX into Virtual DOM elements.
123
+
Turns JSX syntax into Virtual DOM elements. Read more on the [Templating and JSX](./templating-and-jsx.md#the-h-and-fragment-functions) page.
123
124
124
-
-**render()**: a utility method to render a virtual DOM created by `h()` into a container.
125
+
### **render()**:
126
+
127
+
A utility method to render a virtual DOM created by `h()` into a container.
@@ -302,7 +305,8 @@ If your Stencil component library uses `Mixin()` (or `extends`) and *might* be u
302
305
The static-analysis that Stencil uses to find mixed-in classes does not work within 3rd party (node_module) barrel files.
303
306
:::
304
307
308
+
For detailed guidance on using `Mixin()` and `extends` for component architecture, including when to use inheritance vs composition patterns, see the [Extends & Mixins](../guides/extends.md) guide.
305
309
306
-
### [**setTagTransformer()** and **tagTransform()**](../guides/tag-transformation.md):
310
+
### [**setTagTransformer()** and **transformTag()**](../guides/tag-transformation.md):
307
311
308
312
Manage tag name transformation at runtime. Refer to the [Tag Transformation](../guides/tag-transformation.md) page for usage info.
The `@AttachInternals` decorator is used to attach [ElementInternals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals) to a Stencil component.
11
+
This allows you to leverage features such as [Custom States](https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet) and [Form Association](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals#form_association).
12
+
13
+
## Form Association
14
+
15
+
Read the dedicated guide on [Form Associated Components](./form-associated.md) and how to use `@AttachInternals` there.
16
+
17
+
## Custom States
18
+
19
+
You can use the `@AttachInternals` decorator to define [Custom States](https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet) for your component.
Copy file name to clipboardExpand all lines: docs/components/component.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -394,3 +394,7 @@ export class MyParentComponent {
394
394
```
395
395
396
396
The `my-parent-component` includes a reference to the `my-embedded-component` in the `render()` function.
397
+
398
+
## Component Architecture Patterns
399
+
400
+
Stencil supports advanced component architecture patterns including class inheritance and composition. Learn more about organizing component logic with controllers in the [Extends & Mixins](../guides/extends.md) guide.
Copy file name to clipboardExpand all lines: docs/components/templating-and-jsx.md
+70-1Lines changed: 70 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,59 @@ Stencil components are rendered using JSX, a popular, declarative template synta
11
11
12
12
## Basics
13
13
14
-
The `render` function is used to output a tree of components that will be drawn to the screen.
14
+
### The `h` and `Fragment` functions
15
+
16
+
The `h` function (short for "hyperscript") is a factory function that creates virtual DOM elements. When you write JSX like `<div>Hello</div>`, it gets transformed into function calls like `h('div', null, 'Hello')`. The `Fragment` function is used to group a list of children without adding extra nodes to the DOM.
17
+
18
+
#### Set up in Stencil
19
+
20
+
Within your Stencil project, make sure to add or modify your `tsconfig.json` file, adding:
21
+
22
+
```json
23
+
{
24
+
"compilerOptions": {
25
+
"jsx": "react",
26
+
"jsxFactory": "h",
27
+
"jsxFragmentFactory": "Fragment"
28
+
}
29
+
}
30
+
```
31
+
32
+
You will then need to import `h` (and `Fragment` if you plan to use it) from `@stencil/core` at the top of your component file:
(Read more about using the `Fragment` component in the [Complex Template Content](#complex-template-content) section below.)
44
+
45
+
### `jsxImportSource` alternative
46
+
47
+
`jsxImportSource` is a more modern approach that automatically imports the necessary JSX runtime functions instead of manually importing `h`; the compiler automatically imports what it needs from the specified package.
48
+
49
+
#### Set up in Stencil
50
+
51
+
To use `jsxImportSource`, modify your `tsconfig.json` file as follows:
52
+
53
+
```json
54
+
{
55
+
"compilerOptions": {
56
+
"jsx": "react-jsx",
57
+
"jsxImportSource": "@stencil/core"
58
+
}
59
+
}
60
+
```
61
+
62
+
Using this approach means you do not need to manually import `h` or `Fragment` in your component files.
63
+
64
+
### The `render` function
65
+
66
+
The `render` function is used within your component to output a tree of elements that will be drawn to the screen.
15
67
16
68
```tsx
17
69
classMyComponent {
@@ -416,6 +468,23 @@ export class AppHome {
416
468
417
469
In this example we are using `ref` to get a reference to our input `ref={(el) =>this.textInput=elasHTMLInputElement}`. We can then use that ref to do things such as grab the value from the text input directly `this.textInput.value`.
418
470
471
+
## Explicitly setting attributes or properties
472
+
473
+
By default, Stencil tries to intelligently determine whether to set an attribute or (more commonly) a property on an element when using JSX.
474
+
However, in some cases you may want to explicitly set one or the other. You can do this by using the `attr:` or `prop:` prefixes. For example:
475
+
476
+
```tsx
477
+
<inputattr:value="Hello" />
478
+
```
479
+
480
+
will set the `value` attribute on the input element, while:
481
+
482
+
```tsx
483
+
<inputprop:value="Hello" />
484
+
```
485
+
486
+
will explicitly set the `value` property on the input element.
Copy file name to clipboardExpand all lines: docs/config/dev-server.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,6 +130,16 @@ If set to `null`, no route will be registered.
130
130
131
131
Sets the server's port.
132
132
133
+
### `strictPort`
134
+
135
+
**Optional**
136
+
137
+
**Type: `boolean`**
138
+
139
+
**Default: `false`**
140
+
141
+
When set to `true`, the dev server will fail to start if the specified `port` is already in use. When set to `false`, the dev server will try the next available port if the specified port is in use.
0 commit comments