In React Application I want to use web component while using it I am getting an error
TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
I have used web component in one of my project where I have reacted version 16.12, Web component works perfectly while project which has React 16.13.1 version it shows error
I index.js I have imported web component.
Index.js file
import "./webComponent/ImperativeCounter";
ReactDOM.render(
<TranslateProvider translations={translations} defaultLanguage={"sp"}>
<Provider store={store}>
<MainApp />
</Provider>
</TranslateProvider>,
document.getElementById("root")
);
mycomponent.js
<section>
<i-counter ref={counterElement}></i-counter>;
</section>
web component
class ImperativeCounter extends HTMLElement {
constructor() {
super();
this.shadow = this.attachShadow({ mode: 'open'});
this.currentCount = 0;
const templete=`
<b>Count:</b> ${this.currentCount}`;
this.shadow.innerHTML = template;
}
}
window.customElements.define("i-counter", ImperativeCounter);