Skip to content

Instantly share code, notes, and snippets.

@sergey-shpak
Created December 28, 2018 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-shpak/88962fdb4002d9a77d315ee9769e6efb to your computer and use it in GitHub Desktop.
Save sergey-shpak/88962fdb4002d9a77d315ee9769e6efb to your computer and use it in GitHub Desktop.
Hyperapp #v2 Portal Component (Experimental)
import { app, h } from "hyperapp";
import { Portal } from './helpers'
/* Working example, https://codepen.io/sergey-shpak/pen/gZGpjZ */
// --- PORTAL COMPONENT ---
const Modal = (props, child) => Portal(
child, // or h(YourDialogComponent, props, child)
document.getElementById('modal-root') // dom node
)
app({
init: 1,
view: () => h('div', {}, [
'Application',
h(Modal, {}, 'Modal Content')
]),
container: document.getElementById('app-root')
})
import { h } from "hyperapp";
/*
This is implementation of Hyperapp#v2 Portal component
Portal component renders children into a DOM node
that exists outside the DOM hierarchy of the parent component
IMPORTANT! It's not recommended approach to use
unless you really know what you're doing
*/
export const Portal = (child, container) => h('div', {
onCreate: element =>
container.appendChild(document.adoptNode(element))
}, child)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment