Skip to content

Commit

Permalink
Use react-dom method to render the portal to fix missing context
Browse files Browse the repository at this point in the history
  • Loading branch information
romainberger committed May 24, 2016
1 parent 813785f commit 31f32d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"dependencies": {
"babel-core": "^5.8.21",
"babel-loader": "^5.3.2",
"history": "^2.0.1",
"react": "^0.14.0",
"react-dom": "^0.14.0",
"history": "2.0.1",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-image-placeholder": "^1.0.4",
"react-router": "^1.0.0-rc1",
"react-router": "^1.0.3",
"superagent": "^1.8.3",
"webpack": "^1.11.0"
},
Expand Down
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {PropTypes} from 'react'
import ReactDOM from 'react-dom'
import ReactDOM, {unstable_renderSubtreeIntoContainer as renderSubtreeIntoContainer} from 'react-dom'
import isClient from 'is-client'
import assign from 'object-assign'

Expand Down Expand Up @@ -484,23 +484,26 @@ export default class ToolTip extends React.Component {
this.renderPortal(newProps)
}
componentWillUnmount() {
portalNodes[this.props.group] && ReactDOM.unmountComponentAtNode(portalNodes[this.props.group].el)
if (portalNodes[this.props.group]) {
ReactDOM.unmountComponentAtNode(portalNodes[this.props.group].node)
clearTimeout(portalNodes[this.props.group].timeout)
}
}
createPortal() {
portalNodes[this.props.group] = {
el: document.createElement('div'),
node: document.createElement('div'),
timeout: false
}
portalNodes[this.props.group].el.className = 'ToolTipPortal'
document.body.appendChild(portalNodes[this.props.group].el)
portalNodes[this.props.group].node.className = 'ToolTipPortal'
document.body.appendChild(portalNodes[this.props.group].node)
}
renderPortal(props) {
if (!portalNodes[this.props.group]) {
this.createPortal()
}
let {parent, ...other} = props
let parentEl = document.querySelector(parent)
ReactDOM.render(<Card parentEl={parentEl} {...other}/>, portalNodes[this.props.group].el)
renderSubtreeIntoContainer(this, <Card parentEl={parentEl} {...other}/>, portalNodes[this.props.group].node)
}
shouldComponentUpdate() {
return false
Expand Down

0 comments on commit 31f32d9

Please sign in to comment.