# react-data-binding

> do react data binding easily

Latest version **0.4.2** (published 2022-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-data-binding
pnpm add react-data-binding
yarn add react-data-binding
bun add react-data-binding
```

## 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.4.2 |
| Published | 2022-02-21 |
| First published | 2015-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 24.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | yiminghe@gmail.com |
| Maintainers | yiminghe |
| Keywords | react, application, data |

## Links

- npm: https://www.npmjs.com/package/react-data-binding
- Repository: https://github.com/yiminghe/react-data-binding
- Issues: https://github.com/yiminghe/react-data-binding/issues
- npm.io page: https://npm.io/package/react-data-binding

## Dependencies (4)

- [reselect](https://npm.io/package/reselect.md) ~2.0.1
- [prop-types](https://npm.io/package/prop-types.md) 15.x
- [shallowequal](https://npm.io/package/shallowequal.md) ~0.2.2
- [hoist-non-react-statics](https://npm.io/package/hoist-non-react-statics.md) ~1.0.3

## 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.4.2 (latest) — 2022-02-21
- 0.4.1 — 2016-01-15
- 0.4.0 — 2015-12-03
- 0.3.1 — 2015-12-01
- 0.3.0 — 2015-11-30
- 0.2.3 — 2015-11-25
- 0.2.2 — 2015-11-19
- 0.2.1 — 2015-11-18
- 0.2.0 — 2015-11-18
- 0.1.2 — 2015-11-17
- 0.1.1 — 2015-11-17
- 0.1.0 — 2015-11-17
- 0.0.0 — 2015-11-17

## README

# react-data-binding
---

do react data binding in an easy way. inspired by redux.


[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![gemnasium deps][gemnasium-image]][gemnasium-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/react-data-binding.svg?style=flat-square
[npm-url]: http://npmjs.org/package/react-data-binding
[travis-image]: https://img.shields.io/travis/yiminghe/react-data-binding.svg?style=flat-square
[travis-url]: https://travis-ci.org/yiminghe/react-data-binding
[coveralls-image]: https://img.shields.io/coveralls/yiminghe/react-data-binding.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yiminghe/react-data-binding?branch=master
[gemnasium-image]: http://img.shields.io/gemnasium/yiminghe/react-data-binding.svg?style=flat-square
[gemnasium-url]: https://gemnasium.com/yiminghe/react-data-binding
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/react-data-binding.svg?style=flat-square
[download-url]: https://npmjs.org/package/react-data-binding

## examples

http://yiminghe.github.io/react-data-binding

work with redux: http://yiminghe.github.io/react-data-binding/examples/redux.html

```js
@createContainer({
  // specify data need to be concerned
  myUser: 'user'
})
class User extends Component {

  @autobind
  onClick(e) {
    e.preventDefault();
    // trigger re render
    this.props.setStoreState({
      // better use immutable.js
      user: {
        name: 'updated: ' + Date.now()
      }
    });
  }

  render() {
    return (<a href="#" onClick={this.onClick}>{this.props.myUser.name}</a>);
  }
}


@createRootContainer({
  // initial app data
  user: {
    name: 'initial'
  }
})
class App extends React.Component {
  render() {
    return <User/>;
  }
}

ReactDOM.render(<App />, document.getElementById('__react-content'));
```

## api

### Store

build in Store class, you can extend it to create your own store(such as redux store with reducer/dispatch).

### createRootContainer(initialAppData: Object|Store, option: {storeName='store'}): (Function(WrappedComponent:ReactComponent):ReactComponent)

bind the initial global store state to react root component and generate a high order React Component.

will save global store to this.context[storeName].

### createContainer(selector: Object|Function, option: {pure=true, mapStoreProps:Function():Object, storeName='store'}): (Function(WrappedComponent:ReactComponent):ReactComponent)

bind the subset of store state to react child component and generate a high order React Component.

will receive this.context[storeName] as global store.

WrappedComponent will receive the specified subset of store state and return value of option.mapStoreProps(store) as props.

default mapStoreProps will generate the following props:

#### setStoreState(state: Object)

update the global store state and re render react child components which bind to the specified subset of store state.

#### getStoreState()

get the global store state. use with caution.

#### batchStore(callback: Function): Function

return a function which will batch setStoreState calls inside callback.

## Test Case

http://localhost:8111/tests/runner.html?coverage

## Coverage

http://localhost:8111/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8001/tests/runner.html?coverage

## License

react-data-binding is released under the MIT license.

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