Skip to content

vslinko/hoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Higher-order Components Helpers

Higher-order component is awesome way to extend components functionality. But higher-order components have one nasty problem — we have no access to wrapped component. This small module tries to solve that problem.

FAQ

Why do you need access to wrapped component?

I'm using ES6 decorators to wrap my "dumb" components. Sometimes I want to render pure "dumb" components without any decorators. This module gives me access to pure component.

What is "dumb" component?

Please read this article.

API

ES6

import {hocDecorator, getWrappedComponent} from 'hoc';

const smartComponentDecorator = hocDecorator(Component => class SmartComponent {
  render() {
    return <Component />;
  }
});

@smartComponentDecorator
class DumbComponent {
  render() {/* */}
}

console.log(DumbComponent.name); // SmartComponent
console.log(getWrappedComponent(DumbComponent).name); // DumbComponent

ES5

var hoc = require('hoc');

var DumbComponent = React.createClass({
  render: function() {/* */}
});

var SmartComponent = hoc(DumbComponent, React.createClass({
  render: function() {
    return <DumbComponent />;
  }
}))

console.log(SmartComponent.displayName); // SmartComponent
console.log(hoc.getWrappedComponent(SmartComponent).displayName); // DumbComponent

About

[TODO] Higher-order Components Helpers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published