# jedisdb

> React key-value state management solution, accessible in all components

Latest version **0.3.6** (published 2021-12-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.6 |
| Published | 2021-12-30 |
| First published | 2021-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Ahmad Hassan Ansari |
| Maintainers | alhaqhassan |
| Keywords | react, global key-value state, redux alternative, key-value state, global state, global hook, sync state |

## Links

- npm: https://www.npmjs.com/package/jedisdb
- Repository: https://github.com/alhaqhassan/jedis
- Homepage: https://github.com/alhaqhassan/jedis#readme
- Issues: https://github.com/alhaqhassan/jedis/issues
- npm.io page: https://npm.io/package/jedisdb

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

- 0.3.6 (latest) — 2021-12-30
- 0.3.5 — 2021-12-29
- 0.3.4 — 2021-10-24
- 0.3.3 — 2021-10-16
- 0.3.2 — 2021-10-01
- 0.3.1 — 2021-10-01
- 0.3.0 — 2021-10-01
- 0.2.4 — 2021-08-24
- 0.1.6 — 2021-08-21
- 0.1.3 — 2021-08-19
- 0.1.2 — 2021-08-15
- 0.1.0 — 2021-08-15

## README

<h1 align="center">jedisdb</h1>
<h3 align="center">redis like key-value state management solution for React</h3>
<p align="center">Reactive. Redux alternative. Simple and powerful global state management system, accessible through every component.</p>

<h1>Philosophy</h1>

jedisdb is a wrapper for React.JS useState hook. jedisdb makes the hook accessible in every component without the need to explicity pass it down or to create stores, actions, and dispatchers.

<h1>Features 📋</h1>

1. Reactive 
2. State accessable through every components
3. no reducer, no action needed
4. small bundle size

<h1>Basic Usage</h1>

```
npm i jedisdb

or

yarn add jedisdb
```

<h3>happy hacking</h3>

```javascript
import React from 'react'
import useJedis from 'jedisdb'
const Counter = () =>{
/*
if a key is not present in jedis, useJedis('myKey', fallbackValue) will create create that key in jedisdb and then it will return that jedis object,
if key is present it will simply return that jedis object
if we don't pass fallbackValue it will create jedis object with value undefined 
*/
  const counter = useJedis('counter', 0)
  return (
    <div>
      <h1>My counter</h1>
      {counter.state}
      <button onClick={()=>{ counter.state++ }}>+</button>
    </div>
  );
}
```
<h3>Demo:</h3>

Counter [Codesandbox](https://codesandbox.io/s/usejedis-demo1-owozg?file=/src/App.js).

Shopping Cart [Codesandbox](https://codesandbox.io/s/shopping-cart-usejedis-qbgwq?file=/src/App.js).

>`useJedis` returns a react hook so it can only used in react functional components,<br><br>
`selectState` has no side effects, it can be used anywhere,<br>
`createState` creates jedis object without any side effects. <br>
demo: Accessing value in JS funciton [Codesandbox](https://codesandbox.io/s/usejedis-demo2-pdfsm?file=/src/App.js).

<h3>Best Practice</h3>

use `createState` to create jedis object and then use `useJedis` to access it, is considered best practice

```javascript
//myGlobalHook.js
//create jedis object
import {createState} from 'jedisdb'
createState({
    theme: 'dark',
    uesrLevel: 'admin',
    counter: 7
})
```

```javascript
//app.js
//import jedis object in app
import React from 'react';
import Main from './main';
require('./myGlobalHook')
function App() {
  return (
      <Main />
  );
}
export default App;
```

```javascript
//counter.js
//access anywhere
import React from 'react';
import useJedis from "jedisdb";

function Counter() {
  const counter = useJedis('counter') //no need to pass fallback value
  return (
      <>
        {counter.state}
        <button onClick={()=>{ counter.state++ }}>+</button>
      </>
  );
}
export default Counter;
```
demo: [Codesandbox](https://codesandbox.io/s/usejedis-practice-lxrhs?file=/src/App.js)

<br>

# 🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check [issues page](https://github.com/alhaqhassan/jedisdb/issues).

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