Skip to content

Instantly share code, notes, and snippets.

@sergey-shpak
Created October 18, 2019 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergey-shpak/43af11de961514ac0bf2ad033c5c948e to your computer and use it in GitHub Desktop.
Save sergey-shpak/43af11de961514ac0bf2ad033c5c948e to your computer and use it in GitHub Desktop.
Hyperapp#2 Helmet Component
// Hyperapp#2 Helmet Component
// This is based on Hyperapp Portal helper and Lifecycle events helper
// https://gist.github.com/sergey-shpak/88962fdb4002d9a77d315ee9769e6efb
// https://gist.github.com/sergey-shpak/c1e0db3d52019eecb0b5717e8cbf00ad
const Portal = target => (props, child) =>
h('source', { // <- any non-space element
appendChild: target.appendChild.bind(target),
removeChild: target.removeChild.bind(target)
}, child)
export const Helmet = Portal(document.head)
import { app, h } from "hyperapp"
import { Helmet } from '/helpers'
// Pen https://codepen.io/sergey-shpak/pen/yLLaqjY
app({
init: {},
view: state => h('div', {}, [
h(Helmet, {}, [
h('title', {}, ['My custom header'])
]),
'This frame has custom title, check it :)'
]),
node: document.getElementById("app")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment