0
React文檔提供瞭如何在webcomponent內使用反應的示例。但提供的the example是微不足道的,並不足以吸取教訓。特別是它沒有提供關於如何從webcomponent冒出一個事件的信息。將React事件轉換爲Webcomponent事件
假設代碼開始作爲
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(<input onchange={....} value={...}></input>, mountPoint);
}
}
});
document.registerElement('x-search', {prototype: proto});
這將如何進行佈線?