Created
February 6, 2017 15:57
-
-
Save KrofDrakula/21e9bf871d7f0ee047b8392cddb766b2 to your computer and use it in GitHub Desktop.
Customizing node props
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 { options } from 'preact'; | |
import cx from 'classnames'; | |
let old = options.vnode; | |
options.vnode = vnode => { | |
let isElement = typeof vnode.nodeName==='string', | |
props = vnode.attributes || {}, | |
key = props.class ? 'class' : 'className'; | |
if (isElement && props[key] && typeof props[key]==='object') { | |
props[key] = cx(props[key]); | |
} | |
if (old) old(vnode); | |
}; |
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 { options } from 'preact'; | |
let old = options.vnode; | |
options.vnode = vnode => { | |
// vnode.attributes is your props | |
// this gets run on every element. | |
if (old) old(vnode); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment