Skip to content

Instantly share code, notes, and snippets.

@brunocarvalhodearaujo
Created November 29, 2016 13:12
Show Gist options
  • Save brunocarvalhodearaujo/19b016fededb7d608cc342b7a9ef6f15 to your computer and use it in GitHub Desktop.
Save brunocarvalhodearaujo/19b016fededb7d608cc342b7a9ef6f15 to your computer and use it in GitHub Desktop.
Using React in your Web Components
//https://facebook.github.io/react/docs/web-components.html#using-react-in-your-web-components
const proto = Object.create(HTMLElement.prototype, {
attachedCallback: {
value: function() {
const mountPoint = document.createElement('span');
this.createShadowRoot().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);
}
}
});
document.registerElement('x-search', {prototype: proto});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment