# mobx-react-connect

> Connect react component, mobx store and css modules.

Latest version **0.2.7** (published 2017-03-31) · MIT license · 0 weekly downloads

## Install

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

## 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.2.7 |
| Published | 2017-03-31 |
| First published | 2017-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | tvrcgo |
| Maintainers | tvrcgo |
| Keywords | mobx, react, mobx-react |

## Links

- npm: https://www.npmjs.com/package/mobx-react-connect
- Repository: https://github.com/tvrcgo/mobx-react-connect
- Homepage: https://github.com/tvrcgo/mobx-react-connect#readme
- Issues: https://github.com/tvrcgo/mobx-react-connect/issues
- npm.io page: https://npm.io/package/mobx-react-connect

## 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.2.7 (latest) — 2017-03-31
- 0.2.6 — 2017-03-29
- 0.2.5 — 2017-03-29
- 0.2.4 — 2017-03-16
- 0.2.3 — 2017-03-15
- 0.2.2 — 2017-03-11
- 0.2.1 — 2017-03-11
- 0.2.0 — 2017-03-11
- 0.1.0 — 2017-01-16

## README

# mobx-react-connect

Connect react component, mobx store and css module.

**connect( StatelessComponent, Stores, CSSModule )**

### Features
- Only stateless component.
- Map observable stores to component.
- Easy to use css modules.

### Install
```js
npm install mobx-react-connect --save-dev
```

## Example

### Connect component and store.

Store class

```js
// index.store.js
export default class Store {
  @observable id = 0
  constructor (props) {
    const { id } = props
    this.id = id
  }

  @computed
  get userId () {
    return this.id
  }

  @action.bound
  increase() {
    this.id++
  }
}
```

React component.

```js
// index.js
import { connect } from 'mobx-react-connect'
import Store from './index.store'

// functional component
const HelloView = (props, { store }) => {
  return (
    <h1>hello buddy. { store.userId } <a onClick={store.increase}>next</a></h1>
  )
}

export default connect(HelloView, {
  store: Store
})
```

Instantiate component.

```js
import HelloView from './index'

<HelloView id={2} />
```

### Connect component and CSS Modules

You won't need to set className for element like `className={css.title}` any more.

- Set `clazz` attribute for element. Styles in css module will be combined into `className`.
- Multiple style names is available, like `clazz='wrap title'`.
- `clazz` and `className` can be concurrent and styles will be joined together.

```js
import { connect } from 'mobx-react-connect'
import css from './index.css'

const View = () => {
  return (
    <div clazz='green red'></div>
  )
}

export default connect(View, {}, css)
```

`index.css` - Styles for component

```css
.green {
  background-color: green;
}

.red {
  color: red;
}
```

## License
MIT

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