# @keegpt/stook

> A react store with hooks

Latest version **1.0.1** (published 2020-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @keegpt/stook
pnpm add @keegpt/stook
yarn add @keegpt/stook
bun add @keegpt/stook
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-03-08 |
| First published | 2020-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | keegpt |
| Maintainers | josepgomes |
| Keywords | store, hooks, react |

## Links

- npm: https://www.npmjs.com/package/@keegpt/stook
- Repository: https://github.com/keegpt/stook
- Homepage: https://github.com/keegpt/stook#readme
- Issues: https://github.com/keegpt/stook/issues
- npm.io page: https://npm.io/package/@keegpt/stook

## 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.1 (latest) — 2020-03-08
- 1.0.0 — 2020-03-07

## README

# Stook

A react store with hooks!

## Install
```sh
npm install @keegpt/stook --save
```

## Usage
```js
import React from 'react';
import { Provider, useCombinedReducers, createStore } from 'react-stook';

// App.js

import Content from './components/Content';

function App() {

    const elementReducer = (state, action) => {
        switch (action.type) {
            case 'ADD_ONE':
                // action.payload is available here
                return {
                    count: state.count + 1,
                    list: [...state.list, { name: `Element: ${state.count + 1}`}]
                };
            default:
                return state;
            }
    };

    const reducers = useCombinedReducers({
        elements: React.useReducer(elementReducer, { count: 0, list: [] })
        // another: React.useReducer(anotherReducer, initialState)
    });

    return (
        <>
            <Provider store={createStore(reducers)}>
                <Content />
            </Provider>
        </>
    );
}

// Content.js

import React from 'react';
import { connect } from 'react-stook';

function Content({ elements, addElement }) {

    React.useEffect(() => {
        addElement({ random: 1 });
    }, []);

    return (
        <>
            <span>Counter of elements: {elements.count}</span>
        </>
    );
}

function mapStateToProps(state) {
    return {
        elements: state.elements
    }
}

function mapDispatchToProps(dispatch) {
    return {
        addElement: (payload) => dispatch({ type: 'ADD_ONE', payload })
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Content);
```

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