From 14f7813751d1aa817b929c52dd7c462b4c09d2bb Mon Sep 17 00:00:00 2001 From: Kyle Thomson Date: Sat, 15 Dec 2018 15:54:14 +0100 Subject: [PATCH] Use React.createRef() to track child nodes (Remove ReactDOM dependency) --- package.json | 3 +-- src/Transition.js | 13 +++++++++---- webpack.config.js | 8 +------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 8308b511..66c01f26 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,7 @@ ] }, "peerDependencies": { - "react": ">=15.0.0", - "react-dom": ">=15.0.0" + "react": ">=16.3.0" }, "dependencies": { "dom-helpers": "^3.3.1", diff --git a/src/Transition.js b/src/Transition.js index b7669646..22424563 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -1,6 +1,5 @@ import * as PropTypes from 'prop-types' import React from 'react' -import ReactDOM from 'react-dom' import { polyfill } from 'react-lifecycles-compat' import { timeoutsShape } from './utils/PropTypes' @@ -144,6 +143,7 @@ class Transition extends React.Component { this.state = { status: initialStatus } this.nextCallback = null + this.childRef = React.createRef(); } getChildContext() { @@ -221,8 +221,7 @@ class Transition extends React.Component { if (nextStatus !== null) { // nextStatus will always be ENTERING or EXITING. this.cancelNextCallback() - const node = ReactDOM.findDOMNode(this) - + const node = this.childRef.current if (nextStatus === ENTERING) { this.performEnter(node, mounting) } else { @@ -360,8 +359,14 @@ class Transition extends React.Component { delete childProps.onExiting delete childProps.onExited + // Pass the ref to the child element + childProps.ref = this.childRef + if (typeof children === 'function') { - return children(status, childProps) + return React.cloneElement( + children(status), + childProps + ) } const child = React.Children.only(children) diff --git a/webpack.config.js b/webpack.config.js index 8609bb9f..b8e8cf35 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -16,13 +16,7 @@ module.exports = { commonjs2: 'react', commonjs: 'react', amd: 'react', - }, - 'react-dom': { - root: 'ReactDOM', - commonjs2: 'react-dom', - commonjs: 'react-dom', - amd: 'react-dom', - }, + } }, module: { rules: [