# react-state-controller

> An utility Class to easily manage shared state

Latest version **1.2.6** (published 2020-12-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-state-controller
pnpm add react-state-controller
yarn add react-state-controller
bun add react-state-controller
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2020-12-20 |
| First published | 2019-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | wallaroo |
| Maintainers | wallaroo |

## Links

- npm: https://www.npmjs.com/package/react-state-controller
- Repository: git@github.com:wallaroo/react-state-controller
- npm.io page: https://npm.io/package/react-state-controller

## Dependencies (2)

- [auto-bind](https://npm.io/package/auto-bind.md) ^4.0.0
- [nanoevents](https://npm.io/package/nanoevents.md) ^5.1.5

## Recent versions

- 1.2.6 (latest) — 2020-12-20
- 1.2.5 — 2020-12-05
- 1.2.4 — 2020-06-02
- 1.2.3 — 2020-05-31
- 1.2.2 — 2020-05-30
- 1.2.1 — 2020-05-27
- 1.2.0 — 2020-05-27
- 1.1.0 — 2020-04-02
- 1.0.2 — 2020-03-26
- 1.0.1 — 2020-03-26
- 1.0.0 — 2019-09-18

## README

# react-state-controller

This is an utility to easily manage a shared state using hooks.


## install

`> yarn add react-state-controller`

## usage

```typescript
import Controller from 'react-state-controller'

type MyAwesomeState = {
    count: number
    status: "ONLINE" | "OFFLINE"
    data: ComplexType[]
    error?: string | null
}

class MyAwesomeController extends Controller<MyAwesomeState>{
    
    constructor(){
        // initial state
        super({count:0, data:[]});
    }

    async fetchData(){
        const res = await fetch("api/data");
        if (res.ok){
            const data = res.json() as ComplexType[];
            this.setState("data", data);
        }
    }
}

export default new MyAwesomeController();
````

````typescript
import MyAwsomeController from './MyAwesomeController'
function MyAwesomeList(){
    const data = MyAwesomeController.use("data");
    return <ul>{data.map( item => <li>{item}</li>)}</ul>
}

function MyAwesomeButton(){
    return (
        <button onClick={MyAwesomeController.fetchData}>
            Press Me!
        </button>
    )
}

````

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