# istate

> A state management that is inspired on recoil

Latest version **0.0.22** (published 2020-07-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install istate
pnpm add istate
yarn add istate
bun add istate
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.22 |
| Published | 2020-07-02 |
| First published | 2020-06-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 85.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | linq2js |
| Keywords | scope, functional, context, state management, state manager, redux, state |

## Links

- npm: https://www.npmjs.com/package/istate
- Homepage: https://github.com/linq2js/istate#readme
- Issues: https://github.com/linq2js/istate/issues
- npm.io page: https://npm.io/package/istate

## Dependencies (1)

- [iscope](https://npm.io/package/iscope.md) ^0.0.7

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 0.0.22 (latest) — 2020-07-02
- 0.0.20 — 2020-06-30
- 0.0.19 — 2020-06-30
- 0.0.18 — 2020-06-30
- 0.0.17 — 2020-06-30
- 0.0.16 — 2020-06-30
- 0.0.15 — 2020-06-29
- 0.0.14 — 2020-06-25
- 0.0.13 — 2020-06-25
- 0.0.12 — 2020-06-25
- 0.0.11 — 2020-06-25
- 0.0.10 — 2020-06-24
- 0.0.9 — 2020-06-24
- 0.0.8 — 2020-06-23
- 0.0.7 — 2020-06-22
- … 6 more at https://npm.io/package/istate/versions

## README

# istate

A state management that is inspired on recoil

## Simple state

```jsx harmony
import istate from 'istate';

const Count = istate(0);
const Increase = () => {
  const [count, setCount] = Count();
  setCount(count + 1);
};
Increase();
console.log(Count.get()); // 1
```

## Modify state using reducer

```jsx harmony
const Increase = () => {
  const [, setCount] = Count();
  setCount((count) => count + 1);
};
```

## Handle state changing

```jsx harmony
Count.subscribe(() => console.log('count state changed'));
```

## State family

```jsx harmony
const Boxes = istate((id) => ({
  id,
  x: 0,
  y: 0,
}));

const MoveBox = (id, offsetX, offsetY) => {
  const [, setBox] = Boxes(id);
  setBox((box) => ({
    ...box,
    x: box.x + offsetX,
    y: box.y + offsetY,
  }));
};

const ResetBox = (id) => {
  const [, boxApi] = Boxes(id);
  boxApi.reset();
};
```

## State dependencies

```jsx harmony
const Counter = istate(0);
const DoubleCounter = istate(() => {
  const [counter] = Counter();
  return counter * 2;
});
const Increase = () => {
  const [counter, setCounter] = Counter();
  setCounter(counter + 1);
};

Increase(); // Counter = 1, DoubleCounter = 2
Increase(); // Counter = 2, DoubleCounter = 4
```

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