# react-es5-component

> Use `React.Component` in ES5.

Latest version **1.0.4** (published 2015-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-es5-component
pnpm add react-es5-component
yarn add react-es5-component
bun add react-es5-component
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2015-04-01 |
| First published | 2015-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mario Gutierrez |
| Maintainers | mgutz |

## Links

- npm: https://www.npmjs.com/package/react-es5-component
- Repository: https://github.com/mgutz/react-es5-component
- Issues: https://github.com/mgutz/react-es5-component/issues
- npm.io page: https://npm.io/package/react-es5-component

## Recent versions

- 1.0.4 (latest) — 2015-04-01
- 1.0.3 — 2015-03-31
- 1.0.1 — 2015-03-31
- 1.0.0 — 2015-03-31

## README

# react-es5-component

Use `React.Component` in ES5.

This simple library allows React.Component to be used with today's
Javascript without `React.createClass`. React is moving to a simple
class in the future so it's better to start using `React.Component` now.

One nicety this library provides is `bindHandlers`. React.Component
no longer autobinds handlers for you, so you must bind handlers to the
instance. `bindHandlers` binds all functions in the prototype
that match `/^(do|on)[A-Z]/` to the instance.

Instead of this

```js
this.onStoreChange = this.onStoreChange.bind(this)
this.doClick = this.doClick.bind(this)
```

do this

```js
reactComponent.super(this, arguments);
this.bindHandlers(this)

OR

reactComponent.super(this, arguments, true);
```

This library depends on `react` being installed in your project.

## Example

```js
var React = require("react");
var reactComponent = require("react-es5-component");
var MyStore = require("../stores/MyStore");

function MyComponent() {
    // true means autobind handlers
    reactComponent.super(this, arguments, true);
    this.state = MyStore.getState();
}
reactComponent(MyComponent);

MyComponent.propTypes = {location: React.PropTypes.string};

var o = MyComponent.prototype;

o.componentDidMount = function() {
    MyStore.listen(this.onStoreChange);
}

// do* handlers is our convention for UI events
o.doClick = function(e) {
    e.preventDefault();
    // ...
};

// on* handlers is our conventino for store events
o.onStoreChange = function(state) {
    this.setState(state);
}

o.render = function() {
    return (
        <div onClick={this.doClick}>
            Hello {this.state.name}
        </div>
    );
};

module.exports = MyComponent;
```

---
_Source: https://npm.io/package/react-es5-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
