Last active
August 29, 2015 14:23
-
-
Save chrisvfritz/8622d5f42594f9b999f8 to your computer and use it in GitHub Desktop.
An improved interface to React.DOM elements and React.createElement
This file contains hidden or 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
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