Update web-component docs to current standard (#11020)

The documentation example for Web Components uses deprecated Custom Element and Shadow DOM APIs [0]. This change updates the example to the v1 APIs, which are the current standard.

[0] https://developers.google.com/web/fundamentals/web-components/customelements#historysupport
This commit is contained in:
Goffert van Gool
2017-10-02 12:44:57 +02:00
committed by Dominic Gannaway
parent 745c4ab0af
commit 4c855cce0b
+9 -11
View File
@@ -42,17 +42,15 @@ function BrickFlipbox() {
## Using React in your Web Components
```javascript
const proto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function() {
const mountPoint = document.createElement('span');
this.createShadowRoot().appendChild(mountPoint);
class XSearch {
connectedCallback() {
const mountPoint = document.createElement('span');
this.attachShadow({ mode: 'open' }).appendChild(mountPoint);
const name = this.getAttribute('name');
const url = 'https://www.google.com/search?q=' + encodeURIComponent(name);
ReactDOM.render(<a href={url}>{name}</a>, mountPoint);
}
const name = this.getAttribute('name');
const url = 'https://www.google.com/search?q=' + encodeURIComponent(name);
ReactDOM.render(<a href={url}>{name}</a>, mountPoint);
}
});
document.registerElement('x-search', {prototype: proto});
}
customElements.define('x-search', XSearch);
```