# @jitcoder/usestore

> useStore is a library that allows you to maintain the state of your application globally while being able to use certain parts of the state with hooks.

Latest version **1.0.22** (published 2022-07-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install @jitcoder/usestore
pnpm add @jitcoder/usestore
yarn add @jitcoder/usestore
bun add @jitcoder/usestore
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.22 |
| Published | 2022-07-03 |
| First published | 2019-12-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jitcoder |

## Links

- npm: https://www.npmjs.com/package/@jitcoder/usestore
- Repository: https://github.com/jitcoder/usestore
- npm.io page: https://npm.io/package/@jitcoder/usestore

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [eventtarget](https://npm.io/package/eventtarget.md) ^0.1.0
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.149

## Recent versions

- 1.0.22 (latest) — 2022-07-03
- 1.0.21 — 2022-07-03
- 1.0.20 — 2020-03-29
- 1.0.19 — 2020-02-21
- 1.0.18 — 2020-02-21
- 1.0.17 — 2020-02-21
- 1.0.16 — 2020-02-21
- 1.0.15 — 2020-02-21
- 1.0.14 — 2020-02-21
- 1.0.13 — 2020-02-21
- 1.0.12 — 2020-02-21
- 1.0.11 — 2019-12-05
- 1.0.10 — 2019-12-05
- 1.0.9 — 2019-12-05
- 1.0.7 — 2019-12-05
- … 7 more at https://npm.io/package/@jitcoder/usestore/versions

## README

# useStore

useStore is a library that allows you to maintain the state of your application globally while being able to use certain parts of the state with hooks.

Parts of the state can be targeted with a path.
eg. `todo.items`

Whenever that key is changed, the appropriate hooks will be called.

In the below example, if `store.set('todo.items')` is called, it will cause any component that used the useStore hook on key `todo.items` to be re-rendered.

## Example Usage

`api.js`
```javascript
import store from '@jitcoder/usestore';

export const getItems = async () => {
  const results = await axios.get('http://localhost:3001/todo');
  store.set('todo.items', results.data || []);
  return results.data;
}
```

`MyComponent.jsx`
```jsx
import React from 'react';
import { useStore } from '@jitcoder/usestore'

const ItemView = () => {
  const [items] = useStore('todo.items', []);
  return (
    <List>
      {
        items.map((i) => {
          return (
            <ListItem>
              <ListItemText primary={i.title} />
              <ListItemIcon>
                <Button onClick={() => deleteItem(i.id)}>
                  <DeleteIcon />
                </Button>
              </ListItemIcon>
            </ListItem>
          )
        })
      }
    </List>
  );
}
```

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