# js-react-store

> Very small store library to be used in React - mainly to be used locally within components

Latest version **0.0.8** (published 2019-03-22) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install js-react-store
pnpm add js-react-store
yarn add js-react-store
bun add js-react-store
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2019-03-22 |
| First published | 2019-02-25 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mcjazzyfunky |

## Links

- npm: https://www.npmjs.com/package/js-react-store
- Repository: https://github.com/js-works/js-react-store
- Issues: https://github.com/js-works/js-react-store/issues
- npm.io page: https://npm.io/package/js-react-store

## Recent versions

- 0.0.8 (latest) — 2019-03-22
- 0.0.6 — 2019-02-25

## README

# js-react-store

Very small store library to be used in React - mainly to be used locally within components

[![Licence](https://img.shields.io/badge/licence-LGPLv3-blue.svg?style=flat)](https://github.com/js-works/js-react-store/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/js-react-store.svg?style=flat)](https://www.npmjs.com/package/js-react-store)
[![Build status](https://travis-ci.com/js-works/js-react-store.svg)](https://travis-ci.org/js-works/js-react-store)
[![Coverage status](https://coveralls.io/repos/github/js-works/js-react-store/badge.svg?branch=master)](https://coveralls.io/github/js-works/js-react-store?branch=master)

## Installation

npm install --save js-react-store

## Usage
```tsx
import React from 'react'
import ReactDOM from 'react-dom'
import { initStore, useStore } from 'js-react-store'

const { useCallback } = React

function createStore() { 
  const [self, update] = initStore({
    count: initialValue,

    increment() {
      increase(1)
    },

    decrement() {
      increase(-1)
    }
  })

  // private
  function increase(delta: number) {
    update(() => {
      self.count += delta
    })
  }
  
  return self
}

function Counter() {
  const
    store = useStore(createStore),
    increment = useCallback(() => store.increment(), []),
    decrement = useCallback(() => store.decrement(), [])

  return (
    <div>
      <label>Counter: </label>
      <button onClick={decrement}>-</button>
      {` ${store.count} `}
      <button onClick={increment}>+</button>
    </div>
  )
}

ReactDOM.render(<Counter/>, document.getElementById('main-content'))
```

## License

"js-react-store" is licensed under LGPLv3.

## Project status

"js-react-store" is currently in alpha status.

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