Skip to content

Commit

Permalink
use ReactDOM.createPortal if it is available
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenberger committed Sep 15, 2017
1 parent a1539a4 commit 933a5e9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import ownerDocument from './utils/ownerDocument';
* You can think of it as a declarative `appendChild()`, or jQuery's `$.fn.appendTo()`.
* The children of `<Portal/>` component will be appended to the `container` specified.
*/

const useCreatePortal = ReactDOM.createPortal !== undefined;

class Portal extends React.Component {

static displayName = 'Portal';
Expand Down Expand Up @@ -75,9 +78,13 @@ class Portal extends React.Component {
// Save reference for future access.
if (overlay !== null) {
this._mountOverlayTarget();
this._overlayInstance = ReactDOM.unstable_renderSubtreeIntoContainer(
this, overlay, this._overlayTarget
);
if (useCreatePortal) {
this._overlayInstance = ReactDOM.createPortal(overlay, this._overlayTarget);
} else {
this._overlayInstance = ReactDOM.unstable_renderSubtreeIntoContainer(
this, overlay, this._overlayTarget
);
}
} else {
// Unrender if the component is null for transitions to null
this._unrenderOverlay();
Expand Down

0 comments on commit 933a5e9

Please sign in to comment.