# mobx-react-bind

> `npm install mobx-react-bind`

Latest version **0.2.4** (published 2020-07-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2020-07-06 |
| First published | 2020-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hanyon Wu |
| Maintainers | han4wluc |

## Links

- npm: https://www.npmjs.com/package/mobx-react-bind
- npm.io page: https://npm.io/package/mobx-react-bind

## Dependencies (2)

- [injection-js](https://npm.io/package/injection-js.md) ^2.3.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 0.2.4 (latest) — 2020-07-06
- 0.2.4-alpha.2 — 2020-07-06
- 0.2.4-alpha1 — 2020-07-06
- 0.2.3-rc — 2020-07-06
- 0.2.1 — 2020-07-05
- 0.2.1-rc — 2020-07-05
- 0.2.0-rc — 2020-07-03
- 0.1.3 — 2020-05-05
- 0.1.2 — 2020-05-03
- 0.1.1 — 2020-05-03
- 0.1.0 — 2020-05-03

## README

# Installation

`npm install mobx-react-bind`

or

`yarn add mobx-react-bind`

# Usage

## Basic Usage

Define a mobx store
```jsx
import { observable, action } from 'mobx'

class CounterContainer {
  @observable
  count = 0

  @action
  increment = () => {
    this.count = this.count + 1
  }
}
```

Define a react stateless component

```jsx
function CounterView(props) {
  const { container } = props
  return (
    <div onClick={container.increment}>{container.count}</div>
  )
}
```

Bind mobx store and react view

```jsx
import mobxReactBind from 'mobx-react-bind'

const CounterComponent = mobxReactBind({
  container: CounterContainer,
})(CounterView)


// You can then just use it as a usual react component
<CounterComponent />

```

## React lifecycle methods

In the mobx store, you can add a `mount` method that will be called when the component is mounted.

It also accepts a function as a return value that will be called when the component is unmounted.

```jsx
class CounterContainer {
  
  mount = () => {
    console.log('mount')
    return () => {
      console.log('unmount')
    }
  }
}
```

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