Skip to content

Instantly share code, notes, and snippets.

@KrofDrakula
Created February 6, 2017 15:57
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 KrofDrakula/21e9bf871d7f0ee047b8392cddb766b2 to your computer and use it in GitHub Desktop.
Save KrofDrakula/21e9bf871d7f0ee047b8392cddb766b2 to your computer and use it in GitHub Desktop.
Customizing node props
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);
};
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