Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
vnode hook in action
/**
* Module dependencies
*/
const stringify = require('preact-render-to-string')
const preact = require('preact')
const h = preact.h
preact.options.vnode = function (node) {
if (!node.attributes || !node.attributes.class) return
if (typeof node.nodeName === 'function') return
node.attributes.class = node.attributes.class.toString()
}
/**
* Initialize `App`
*/
const App = (props) => (
h(Header, props)
)
const Header = (props) => (
h('div', { class: header() }, `hello ${props.name}!`)
)
function header () {
return {
toString: () => 'header'
}
}
/**
* Browser
*/
if (typeof document !== 'undefined') {
preact.render(App({ name: 'matt' }), document.body, document.body.firstChild)
} else {
console.log(stringify(App({ name: 'matt' })))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.