# react-bind-mixin

> A React mixin used to simplify the binding between components and data stores.

Latest version **0.0.9** (published 2015-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-bind-mixin
pnpm add react-bind-mixin
yarn add react-bind-mixin
bun add react-bind-mixin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2015-04-05 |
| First published | 2015-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Holman Gao |
| Maintainers | golmansax |
| Keywords | react, mixin, flux, binding, store |

## Links

- npm: https://www.npmjs.com/package/react-bind-mixin
- Repository: http://github.com/golmansax/react-bind-mixin
- Homepage: https://github.com/golmansax/react-bind-mixin
- Issues: https://github.com/golmansax/react-bind-mixin/issues
- npm.io page: https://npm.io/package/react-bind-mixin

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2015-04-05
- 0.0.8 — 2015-03-22
- 0.0.7 — 2015-03-22
- 0.0.6 — 2015-03-18
- 0.0.5 — 2015-03-11
- 0.0.4 — 2015-03-11
- 0.0.3 — 2015-03-11
- 0.0.2 — 2015-03-11
- 0.0.1 — 2015-03-11

## README

# React Bind Mixin

[![Build Status](https://travis-ci.org/golmansax/react-bind-mixin.svg?branch=master)](https://travis-ci.org/golmansax/react-bind-mixin)
[![Code Climate](https://codeclimate.com/github/golmansax/react-bind-mixin/badges/gpa.svg)](https://codeclimate.com/github/golmansax/react-bind-mixin)
[![Test Coverage](https://codeclimate.com/github/golmansax/react-bind-mixin/badges/coverage.svg)](https://codeclimate.com/github/golmansax/react-bind-mixin)

A React mixin used to simplify the binding between components and data stores.
Can be plugged into virtually any Flux implementation!

## Sample Usage
Given a Store with the following API:
```js
var MyStore = {
  addChangeListener: function (callback) {
    // bind callback to changes to Store
  },

  removeChangeListener: function (callback) {
    // remove callback binding
  }
};
```
We can bind a React component to the Store in a simple way:
```jsx
var BindMixin = require('react-bind-mixin');
var Component = React.createClass({
  mixins: [BindMixin(MyStore, 'getStateFromStore')],

  // this.props passed in for 'props'
  // except for when called from componentWillReceiveProps (newProps passed in)
  getStateFromStore: function (props) {
    return {
      // 'getValue' API is custom to the store implementation
      value: MyStore.getValue(props.id)
    };
  },

  render: function () {
    return <div>{this.state.value}</div>;
  }
});
```

Now the state of our component will be:
* initialized with the initial value of the Store
* updated when the Store is changed
* updated when props are changed

## Makes testing easy!

With this straight-forward implementation, it becomes trivial to test the
component.  Simply mock out the associated store functions.  Below is an
example using the Mocha/sinon test framework.

```jsx
sinon.stub(MyStore, 'getValue');
MyStore.getValue.returns('Hello');
var component = React.addons.TestUtils.renderIntoDocument(<Component />);
expect(component.text).to.equal('Hello');

MyStore.getValue.returns('Goodbye');
expect(component.text).to.equal('Goodbye');
```

## Installation
```bash
# Node
npm install react-bind-mixin --save
```

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