mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Only define MyElement when needed (#11069)
This commit is contained in:
@@ -12,24 +12,23 @@ class HelloWorld extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
// Babel breaks web components.
|
||||
// https://github.com/w3c/webcomponents/issues/587
|
||||
// eslint-disable-next-line no-new-func
|
||||
const MyElement = new Function(
|
||||
'React',
|
||||
'ReactDOM',
|
||||
'HelloWorld',
|
||||
`
|
||||
return class MyElement extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
const shadowRoot = this.attachShadow({ mode:'open' });
|
||||
ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
|
||||
}
|
||||
}`
|
||||
)(React, ReactDOM, HelloWorld);
|
||||
|
||||
if (supportsCustomElements) {
|
||||
// Babel breaks web components.
|
||||
// https://github.com/w3c/webcomponents/issues/587
|
||||
// eslint-disable-next-line no-new-func
|
||||
const MyElement = new Function(
|
||||
'React',
|
||||
'ReactDOM',
|
||||
'HelloWorld',
|
||||
`
|
||||
return class MyElement extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
const shadowRoot = this.attachShadow({ mode:'open' });
|
||||
ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
|
||||
}
|
||||
}`
|
||||
)(React, ReactDOM, HelloWorld);
|
||||
customElements.define('my-element', MyElement);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user