Skip to content

Instantly share code, notes, and snippets.

@gilbox
Created June 30, 2015 04:56
Show Gist options
  • Save gilbox/c1415ac4304076326b8b to your computer and use it in GitHub Desktop.
Save gilbox/c1415ac4304076326b8b to your computer and use it in GitHub Desktop.
Functional React: component function
// @param additionalMixins? {Array|Object}
// @param renderFn {Function}
// @returns Component
function component(additionalMixins, renderFn) {
renderFn = renderFn || additionalMixins;
additionalMixins = (additionalMixins instanceof Function) ? [] : [].concat(additionalMixins);
const mixins = [ComponentRenderMixin,
staticFunctionsMixin]
.concat(additionalMixins);
const render = function() {
console.log(`render <${renderFn.name} />`);
return renderFn.call(this, this.props, this.props.statics, this.props.children);
};
const displayName = renderFn.name;
return React.createClass({displayName, mixins, render});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment