# rstates

> RStates - A simple js state library

Latest version **1.0.0** (published 2021-04-22) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-04-22 |
| First published | 2021-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Quozzo |
| Maintainers | quozzo |
| Keywords | state, nodejs, backend, states, react, native, web, react-native, react-native-web |

## Links

- npm: https://www.npmjs.com/package/rstates
- Repository: https://github.com/Quozzo/rstates
- Homepage: https://github.com/Quozzo/rstates#readme
- Issues: https://github.com/Quozzo/rstates/issues
- npm.io page: https://npm.io/package/rstates

## 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

- 1.0.0 (latest) — 2021-04-22

## README

# RStates

A super small, simple and fast ⚡ JavaScript state library

[![NPM](https://nodei.co/npm/rstates.png)](https://npmjs.org/package/rstates)

![GitHub issues](https://img.shields.io/github/issues/quozzo/rstates.svg)
![license](https://img.shields.io/github/license/quozzo/rstates.svg)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/rstates)
![npm](https://img.shields.io/npm/v/rstates.svg)

## Why a fork?

RStates uses an implementation similar to React's useState hook which alleviates issues such as removing empty properties and being unable to use arrays directly within the state.

## Install

```sh
npm i rstates
```

## Usage

```js
const rstates = require('rstates')

const myState = rstates({ counter: 0 })

function onUpdate(state) {
	console.log('onUpdate: counter changed to ', state.counter)
}

myState.subscribe(onUpdate)

// Updating with an object
myState.setState({ counter: ++myState.state.counter })
// => onUpdate: counter changed to  1

// Updating with a function
myState.setState(state => ({ counter: ++state.counter }))
// => onUpdate: counter changed to  2
```

## API

```js
const initialState = {};
const stateInstance = rstates(initialState);
/* => returns state Instance
{
  state,
  subscribers,
  setState,
  subscribe,
  unsubscribe,
};
*/

// Get the state
stateInstance.state;

// Change the state
stateInstance.setState(<object or a function that returns and object>);
// => returns a promise

// Subscribe to state changes
stateInstance.subscribe(<function that will be called with the state on each update>);


// Unsubscribe from state changes
stateInstance.unsubscribe(<function that already subscribed>);

```

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