Skip to content

Instantly share code, notes, and snippets.

@developit
Last active April 13, 2016 17:13
Show Gist options
  • Select an option

  • Save developit/6adf4f42e5e196702124262a32fe2914 to your computer and use it in GitHub Desktop.

Select an option

Save developit/6adf4f42e5e196702124262a32fe2914 to your computer and use it in GitHub Desktop.
import { h } from 'preact';
export default function cloneElement(vnode, props, ...children) {
return h(
vnode.nodeName,
extend(extend({}, vnode.attributes || {}), props),
children.length ? children : vnode.children
);
}
// Object.assign() ponyfill
function extend(obj, props) {
for (let i in props) {
if (props.hasOwnProperty(i)) {
obj[i] = props[i];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment