Skip to content

Instantly share code, notes, and snippets.

@chrisvfritz
Last active August 29, 2015 14:23
Show Gist options
  • Save chrisvfritz/8622d5f42594f9b999f8 to your computer and use it in GitHub Desktop.
Save chrisvfritz/8622d5f42594f9b999f8 to your computer and use it in GitHub Desktop.
An improved interface to React.DOM elements and React.createElement
window.$ = function(element, propsOrChildren, childrenIfProps){
var props, children;
if ((propsOrChildren != null && propsOrChildren instanceof Array) || !(propsOrChildren instanceof Object)) {
props = null;
children = propsOrChildren;
} else {
props = propsOrChildren;
children = childrenIfProps;
}
return React.createElement(element, props, children);
}
Object.keys(React.DOM).forEach(function(elementName){
window['$' + elementName] = function(props, children){
return $(elementName, props, children);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment