# staat-react

> ## The React bindings for Staat

Latest version **1.3.0-beta.1** (published 2019-07-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install staat-react
pnpm add staat-react
yarn add staat-react
bun add staat-react
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0-beta.1 |
| Published | 2019-07-07 |
| First published | 2019-01-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 77.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eric Mackrodt |
| Maintainers | ericmackrodt |

## Links

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

## Recent versions

- 1.3.0-beta.1 (latest) — 2019-07-07
- 1.2.0 — 2019-04-08
- 1.2.0-beta.1 — 2019-02-18
- 1.1.1 — 2019-01-29
- 1.1.1-beta.6 — 2019-01-23
- 1.1.1-beta.5 — 2019-01-23
- 1.1.1-beta.4 — 2019-01-11
- 1.1.1-beta.3 — 2019-01-10
- 1.1.1-beta.2 — 2019-01-06
- 1.1.0 — 2019-01-06

## README

# Staat/React

## The React bindings for Staat

## Basic usage

```tsx
import staat from 'staat';
import reactStaat from 'staat-react';
import React from 'react';
import ReactDOM from 'react-dom';

const initialState = {
  count: 0
};

const state = staat(
  {
    add(currentState: typeof initialState, value: number) {
      return { ...currentState, count: currentState.count + value };
    },
    subtract(currentState: typeof initialState, value: number) {
      return { ...currentState, count: currentState.count - value };
    }
  },
  initialState
);

const { Provider, connect } = reactStaat(state);

const Calculator: React.StatelessComponent<CalculatorProps> = props => {
  return (
    <div>
      <button onClick={() => props.add(10)}>Add</button>
      <button onClick={() => props.subtract(3)}>Subtract</button>
      <div>{props.count}</div>
    </div>
  );
};

type TransformerProps = {
  add: typeof state.add;
  subtract: typeof state.subtract;
};

type OwnProps = {};

type CalculatorProps = TransformerProps & typeof initialState & OwnProps;

const Calc = connect<OwnProps, typeof initialState, TransformerProps>(
  ({ calculator }) => {
    return {
      count: calculator.count
    };
  },
  () => {
    return {
      add: calculator.add,
      subtract: calculator.subtract
    };
  }
)(Calculator);

ReactDOM.render(
  <Provider>
    <Calc />
  </Provider>,
  document.getElementById('entry')
);
```

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