1.0.2 • Published 6 years ago

classless-component v1.0.2

Weekly downloads
12
License
MIT
Repository
github
Last release
6 years ago

Classless Component

travis devDependency Status

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 = compose(Component, Preact.h,
  function componentWillMount () {
    ...
  }
)

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

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago