import React from 'react'
import { createPortal } from 'react-dom'

export default class Dialog extends React.Component {
  constructor(props) {
    super(props)

    const doc = window.document
    this.node = doc.createElement('div')
    doc.body.appendChild(this.node)
  }

  render() {
    const { children } = this.props
    return createPortal(children, this.node)
  }

  componentWillUnmount() {
    window.document.body.removeChild(this.node);
  }
}
