# cato-react-store

> A simple and easy to use Flux like state manager for react and react-native apps

Latest version **1.1.1** (published 2019-04-17) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-04-17 |
| First published | 2018-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 169.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Cato Analytics Ltd. |
| Maintainers | aminchoroomi |
| Keywords | react, react-native, redux, state management |

## Links

- npm: https://www.npmjs.com/package/cato-react-store
- Repository: https://github.com/cato-analytics/cato-react-store
- Homepage: https://github.com/cato-analytics/cato-react-store#readme
- Issues: https://github.com/cato-analytics/cato-react-store/issues
- npm.io page: https://npm.io/package/cato-react-store

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^16.4.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.1

## 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.1.1 (latest) — 2019-04-17
- 1.1.0 — 2019-04-09
- 1.0.9 — 2018-06-06
- 1.0.8 — 2018-06-06
- 1.0.7 — 2018-06-06
- 1.0.6 — 2018-06-06
- 1.0.5 — 2018-06-06
- 1.0.4 — 2018-06-06
- 1.0.3 — 2018-06-06
- 1.0.2 — 2018-06-06
- 1.0.1 — 2018-06-06
- 1.0.0 — 2018-06-06

## README

# Cato React Store

A simple and easy to use Flux like state manager for react and react-native apps.


## Getting Started

You can either install the package via `npm` or `yarn` package managers, 
or you can download and add [src/index.js](src/index.js) directly to your project.

### Installing

```
npm install cato-react-store --save
```
or
```
yarn add cato-react-store
```

## Usage

### src/index.js

First import the `StoreProvider`

```
import { StoreProvider } from 'cato-react-store';
```

Then wrap the `App` component in it

```
ReactDOM.render(
  <StoreProvider>
    <App />
  </StoreProvider>
  , document.getElementById('root'));
```

### components
1. Stateful Components (Also works with PureComponents)

```
import React, { Component } from 'react';
import { connect } from 'cato-react-store';

const mapping = (store, originalProps) => ({
  prop1: store.getState().value1,
  prop2: store.getState().value2,
  action: () => {
    store.setState({
      value1: 'New Value'
    })
  },
  asyncAction: async (input) => {
    let result = await someAsyncFunction(input);
    store.setState({
      value2: result
    })
  }
});

class StatefulComponent extends Component {
  render() {
    let { prop1, prop2, action, asyncAction } = this.props
    return (
      <div>
        <h1>{prop1}</h1>
        <h2>{prop2}</h2>
        <hr />
        <button onClick={e => action()}>Do Action</button>
        <button onClick={e => asyncAction()}>Do Async Action</button>
      </div>
    );
  }
}

export default connect(mapping)(StatefulComponent);
```

2. Stateless Components
```
import React from 'react';
import { connect } from 'cato-react-store';

const mapping = (store, originalProps) => ({
  prop1: store.getState().value1,
  prop2: store.getState().value2,
  action: () => {
    store.setState({
      value1: 'New Value'
    })
  },
  asyncAction: async (input) => {
    let result = await someAsyncFunction(input);
    store.setState({
      value2: result
    })
  }
});

const StatelessComponent = ({ prop1, prop2, action, asyncAction }) => {
  return (
    <div>
      <h1>{prop1}</h1>
      <h2>{prop2}</h2>
      <hr />
      <button onClick={e => action()}>Do Action</button>
      <button onClick={e => asyncAction()}>Do Async Action</button>
    </div>
  );
};

export default connect(mapping)(StatelessComponent);
```


## Authors

* **Amin Choroomi** - [Cato Analytics](https://catoanalytics.com)


## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details

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