Spaces:
Runtime error
Runtime error
Update src/containers/dom-element-renderer.jsx
Browse files
src/containers/dom-element-renderer.jsx
CHANGED
@@ -19,9 +19,11 @@ class DOMElementRenderer extends React.Component {
|
|
19 |
this.setContainer = this.setContainer.bind(this);
|
20 |
}
|
21 |
componentDidMount () {
|
|
|
22 |
this.container.appendChild(this.props.domElement);
|
23 |
}
|
24 |
componentWillUnmount () {
|
|
|
25 |
if (this.props.domElement.parentNode !== this.container) return;
|
26 |
this.container.removeChild(this.props.domElement);
|
27 |
}
|
@@ -29,21 +31,28 @@ class DOMElementRenderer extends React.Component {
|
|
29 |
this.container = c;
|
30 |
}
|
31 |
render () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
// Apply props to the DOM element, so its attributes
|
33 |
// are updated as if it were a normal component.
|
34 |
// Look at me, I'm the React now!
|
35 |
Object.assign(
|
36 |
-
|
37 |
omit(this.props, ['domElement', 'children', 'style'])
|
38 |
);
|
39 |
|
40 |
// Convert react style prop to dom element styling.
|
41 |
if (this.props.style) {
|
42 |
-
|
43 |
}
|
44 |
if (this.container) {
|
45 |
this.container.innerHTML = '';
|
46 |
-
this.container.appendChild(
|
47 |
}
|
48 |
|
49 |
return <div ref={this.setContainer} />;
|
@@ -55,4 +64,4 @@ DOMElementRenderer.propTypes = {
|
|
55 |
style: stylePropType
|
56 |
};
|
57 |
|
58 |
-
export default DOMElementRenderer;
|
|
|
19 |
this.setContainer = this.setContainer.bind(this);
|
20 |
}
|
21 |
componentDidMount () {
|
22 |
+
if (!this.props.domElement) return;
|
23 |
this.container.appendChild(this.props.domElement);
|
24 |
}
|
25 |
componentWillUnmount () {
|
26 |
+
if (!this.props.domElement) return;
|
27 |
if (this.props.domElement.parentNode !== this.container) return;
|
28 |
this.container.removeChild(this.props.domElement);
|
29 |
}
|
|
|
31 |
this.container = c;
|
32 |
}
|
33 |
render () {
|
34 |
+
let element = this.props.domElement;
|
35 |
+
// if we where never passed an element, ensure Object.assign doesnt error out about
|
36 |
+
if (!element) {
|
37 |
+
element = document.createElement('span');
|
38 |
+
element.innerText = 'ERR: No element provided';
|
39 |
+
console.warn('No element provided to the DOMElementRenderer');
|
40 |
+
}
|
41 |
// Apply props to the DOM element, so its attributes
|
42 |
// are updated as if it were a normal component.
|
43 |
// Look at me, I'm the React now!
|
44 |
Object.assign(
|
45 |
+
element,
|
46 |
omit(this.props, ['domElement', 'children', 'style'])
|
47 |
);
|
48 |
|
49 |
// Convert react style prop to dom element styling.
|
50 |
if (this.props.style) {
|
51 |
+
element.style.cssText = Style.string(this.props.style);
|
52 |
}
|
53 |
if (this.container) {
|
54 |
this.container.innerHTML = '';
|
55 |
+
this.container.appendChild(element);
|
56 |
}
|
57 |
|
58 |
return <div ref={this.setContainer} />;
|
|
|
64 |
style: stylePropType
|
65 |
};
|
66 |
|
67 |
+
export default DOMElementRenderer;
|