UNPKG

713 BJavaScriptView Raw
1import React, {Component} from 'react';
2import PropTypes from 'prop-types';
3
4export default class Renderer extends Component {
5 static propTypes = {
6 className: PropTypes.string,
7 nodes: PropTypes.array
8 };
9
10 componentDidMount() {
11 const {nodes} = this.props;
12 if (!this.node || !nodes || !nodes.length) {
13 return;
14 }
15 const fragment = document.createDocumentFragment();
16 nodes.forEach(nodeToRender => fragment.appendChild(nodeToRender));
17
18 this.node.appendChild(fragment);
19 }
20
21 nodeRef = node => {
22 this.node = node;
23 };
24
25 render() {
26 const {className} = this.props;
27 return (
28 <div
29 className={className}
30 ref={this.nodeRef}
31 />
32 );
33 }
34}