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
If you render a tag with a dash, like `<my-element>`, React will assume you want to render a [custom HTML element.](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)
172
+
>>>>>>> 27d86ffe6ec82e3642c6490d2187bae2271020a4
169
173
170
174
組み込みのブラウザ HTML 要素を [`is`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is) 属性を用いてレンダーする場合も、カスタム要素として扱われます。
171
175
176
+
#### Setting values on custom elements {/*attributes-vs-properties*/}
177
+
178
+
Custom elements have two methods of passing data into them:
179
+
180
+
1) Attributes: Which are displayed in markup and can only be set to string values
181
+
2) Properties: Which are not displayed in markup and can be set to arbitrary JavaScript values
182
+
183
+
By default, React will pass values bound in JSX as attributes:
184
+
185
+
```jsx
186
+
<my-element value="Hello, world!"></my-element>
187
+
```
188
+
189
+
Non-string JavaScript values passed to custom elements will be serialized by default:
190
+
191
+
```jsx
192
+
// Will be passed as `"1,2,3"` as the output of `[1,2,3].toString()`
193
+
<my-element value={[1,2,3]}></my-element>
194
+
```
195
+
196
+
React will, however, recognize an custom element's property as one that it may pass arbitrary values to if the property name shows up on the class during construction:
#### Listening for events on custom elements {/*custom-element-events*/}
235
+
236
+
A common pattern when using custom elements is that they may dispatch [`CustomEvent`s](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) rather than accept a function to call when an event occur. You can listen for these events using an `on` prefix when binding to the event via JSX.
Events are case-sensitive and support dashes (`-`). Preserve the casing of the event and include all dashes when listening for custom element's events:
0 commit comments