 
 
   render: =>
-    createPortal @renderPortalContent(), portals[0]
+    @portal ?= document.createElement('div')
+    createPortal @renderPortalContent(), @portal
 
 
   renderPortalContent: =>



  componentDidMount: =>
    document.addEventListener 'keydown', @handleEsc


  componentDidUpdate: (prevProps) =>

import { createPortal } from 'react-dom'

export class Modal extends PureComponent
  roots = document.getElementsByClassName('js-react-modal')


  @inTree: (event) ->
    roots[0] in event.composedPath()


  constructor: ->
