Classless Component
If you use React, Preact, or Inferno, but don't want to use the class
syntax because you've read articles by Eric Elliott and others that have lead you to favour object composition over class inheritance, then this utility is for you.
Under Rapid Development!
Annoyed that recompose was coupled to React and Incompose to Inferno, and wanting a solution for Preact, I set out to see how hard a de-coupled library would be. Instead of assuming one of the aforementioned libraries, the compose
function accepts the Base Component Class (React.Component
, InfernoComponent
, ...) and the hyperscript function (React.createElement
, Preact.h
, ...) as the first two parameters.
Installation
$ npm install --save classless-component
Usage
As this is in rapid development, and by no means stable, please refer to the test.js
file for working examples.
Functions as params are deprecated.
Previously, the following worked:
const Comp =
And the name of the function would be magically assigned to a new object. This caused issues when using UglifyJS to minify the code (as the function referance name was no longer guaranteed).
Instead, each param should be an explicit object with property names for render
, componentDidMount
, etc.
Acknowledgments
Based on preact-classless-component by Laurence Dorman.
License
MIT