Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use React.createRef() to track child nodes (Remove ReactDOM dependency) #437

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
]
},
"peerDependencies": {
"react": ">=15.0.0",
"react-dom": ">=15.0.0"
"react": ">=16.3.0"
},
"dependencies": {
"dom-helpers": "^3.3.1",
Expand Down
13 changes: 9 additions & 4 deletions src/Transition.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -144,6 +143,7 @@ class Transition extends React.Component {
this.state = { status: initialStatus }

this.nextCallback = null
this.childRef = React.createRef();
}

getChildContext() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down