Created
October 18, 2019 08:19
-
-
Save sergey-shpak/43af11de961514ac0bf2ad033c5c948e to your computer and use it in GitHub Desktop.
Hyperapp#2 Helmet Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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