diff --git a/docs/docs/web-components.md b/docs/docs/web-components.md index 1012ea795b..0cdc057e66 100644 --- a/docs/docs/web-components.md +++ b/docs/docs/web-components.md @@ -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({name}, mountPoint); - } + const name = this.getAttribute('name'); + const url = 'https://www.google.com/search?q=' + encodeURIComponent(name); + ReactDOM.render({name}, mountPoint); } -}); -document.registerElement('x-search', {prototype: proto}); +} +customElements.define('x-search', XSearch); ```