import { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDom from 'react-dom';

const useCreatePortal = typeof ReactDom.unstable_createPortal === 'function';

class Portal extends Component {
  componentWillMount() {
    this.popup = document.createElement('div');
    document.body.appendChild(this.popup);
    this.renderLayer();
  }

  componentDidUpdate() {
    this.renderLayer();
  }

  componentWillUnmount() {
    if (!useCreatePortal) {
      ReactDom.unmountComponentAtNode(this.popup);
    }
    document.body.removeChild(this.popup);
  }

  renderLayer() {
    if (!useCreatePortal) {
      ReactDom.unstable_renderSubtreeIntoContainer(this, this.props.children, this.popup);
    }
  }

  render() {
    if (useCreatePortal) {
      return ReactDom.unstable_createPortal(this.props.children, this.popup);
    }
    return null;
  }
}

Portal.propTypes = {
  children: PropTypes.node, // eslint-disable-line
};

export default Portal;

import { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDom from 'react-dom';

class Portal extends Component {
  componentWillMount() {
    this.popup = document.createElement('div');
    document.body.appendChild(this.popup);
    this.renderLayer();
  }

  componentDidUpdate() {
    this.renderLayer();
  }

  componentWillUnmount() {
    ReactDom.unmountComponentAtNode(this.popup);
    document.body.removeChild(this.popup);
  }

  renderLayer() {
    ReactDom.unstable_renderSubtreeIntoContainer(this, this.props.children, this.popup);
  }

  render() {
    return null;
  }
}

Portal.propTypes = {
  children: PropTypes.node, // eslint-disable-line
};

export default Portal;

--- 
+++ 
@@ -1,6 +1,8 @@
 import { Component } from 'react';
 import PropTypes from 'prop-types';
 import ReactDom from 'react-dom';
+
+const useCreatePortal = typeof ReactDom.unstable_createPortal === 'function';
 
 class Portal extends Component {
   componentWillMount() {
@@ -14,15 +16,22 @@
   }
 
   componentWillUnmount() {
-    ReactDom.unmountComponentAtNode(this.popup);
+    if (!useCreatePortal) {
+      ReactDom.unmountComponentAtNode(this.popup);
+    }
     document.body.removeChild(this.popup);
   }
 
   renderLayer() {
-    ReactDom.unstable_renderSubtreeIntoContainer(this, this.props.children, this.popup);
+    if (!useCreatePortal) {
+      ReactDom.unstable_renderSubtreeIntoContainer(this, this.props.children, this.popup);
+    }
   }
 
   render() {
+    if (useCreatePortal) {
+      return ReactDom.unstable_createPortal(this.props.children, this.popup);
+    }
     return null;
   }
 }
Add support for new React Core (v16)

Old react (v15) still working