-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorld.tsx
More file actions
34 lines (29 loc) · 944 Bytes
/
HelloWorld.tsx
File metadata and controls
34 lines (29 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as React from 'react';
import {render, unmountComponentAtNode} from 'react-dom';
export default class HelloWorld extends React.Component<any, any> {
render() {
return <span>Hello {this.props.children}</span>
}
}
class CustomElement extends HTMLElement {
mountPoint: any
// componentAttributes = {}; // TODO: add example of usage
// componentProperties = {}; // TODO: add example of usage
constructor() {
super();
}
connectedCallback() {
this.update();
}
disconnectedCallback() {
unmountComponentAtNode(this.mountPoint);
}
update() {
if (!this.mountPoint) {
this.mountPoint = document.createElement('span');
this.attachShadow({mode: 'open'}).appendChild(this.mountPoint);
}
render(<HelloWorld>{this.innerHTML}</HelloWorld>, this.mountPoint);
}
}
customElements.define('hello-world', CustomElement);