# upstore

> providerless state container with React bindings

Latest version **0.1.9** (published 2018-01-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.9 |
| Published | 2018-01-23 |
| First published | 2018-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jon Stuebe |
| Maintainers | jonstuebe |
| Keywords | react, javascript, redux, store |

## Links

- npm: https://www.npmjs.com/package/upstore
- Repository: https://github.com/jonstuebe/upstore
- Homepage: https://github.com/jonstuebe/upstore#readme
- Issues: https://github.com/jonstuebe/upstore/issues
- npm.io page: https://npm.io/package/upstore

## 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.1.9 (latest) — 2018-01-23
- 0.1.8 — 2018-01-23
- 0.1.7 — 2018-01-20
- 0.1.6 — 2018-01-20
- 0.1.5 — 2018-01-20
- 0.1.4 — 2018-01-20
- 0.1.2 — 2018-01-20
- 0.1.1 — 2018-01-20
- 0.1.0 — 2018-01-20

## README

# Upstore

providerless state container with React bindings. Includes UMD build

[![version](https://img.shields.io/npm/v/upstore.svg?style=flat-square)](https://www.npmjs.com/package/@jonstuebe/upstore) [![build](https://travis-ci.org/jonstuebe/upstore.svg?branch=master)](https://www.npmjs.com/package/@jonstuebe/upstore)

## Install

### npm

```shell
npm i -s upstore
```

or

### yarn

```shell
yarn add upstore
```

## Usage

[see online at codesandbox](https://codesandbox.io/s/0o0okxlrjp)

### store.js

```javascript
import UpStore from "upstore";
import { get } from "axios";

const counterReducer = (counter, action) => {
  switch (action.type) {
    case "DECREMENT":
      counter--;
      return counter;
    case "INCREMENT":
      counter++;
      return counter;
    default:
      return counter;
  }
};
const fetchDataReducer = (data, action) => {
  switch (action.type) {
    case "FETCH_DATA":
      data = action.data;
  }
  return data;
};
const reducers = {
  counter: counterReducer,
  data: fetchDataReducer
};

const store = new UpStore({ counter: 0 }, reducers);

export const actions = store.actions({
  decrement: async () => {
    return {
      type: "DECREMENT"
    };
  },
  increment: () => {
    return {
      type: "INCREMENT"
    };
  },
  fetchData: async url => {
    const data = await get(url).then(response => response.data);
    return {
      type: "FETCH_DATA",
      data
    };
  }
});

export default store;
```

### App.js

```javascript
import React from "react";
import Counter from "./components/Counter";
import FetchData from "./components/FetchData";

export default () => (
  <div>
    <Counter />
    <FetchData />
  </div>
);
```

### components/Counter.js

```javascript
import React, { Fragment } from "react";

import store, { actions } from "../store";
import { Connect } from "upstore";

export default () => (
  <Fragment>
    <Connect
      store={store}
      filterState={state => {
        return { counter: state.counter };
      }}
    >
      {({ state }) => (
        <div>
          <h2>Counter Example</h2>
          <p>{state.counter}</p>
          <button onClick={actions.decrement}>decrement</button>
          <button onClick={actions.increment}>increment</button>
        </div>
      )}
    </Connect>
  </Fragment>
);
```

### components/FetchData.js

```javascript
import React, { Fragment } from "react";

import store, { actions } from "../store";
import { Connect } from "upstore";

export default () => (
  <Fragment>
    <Connect
      store={store}
      filterState={state => {
        return { data: state.data };
      }}
    >
      {({ state }) => {
        return (
          <div>
            <h2>Async Data Fetch Example</h2>
            <button
              onClick={actions.fetchData.bind(
                null,
                "https://www.reddit.com/r/mechanical_gifs.json"
              )}
            >
              fetch data
            </button>
            <pre>{JSON.stringify(state.data, null, 2)}</pre>
          </div>
        );
      }}
    </Connect>
  </Fragment>
);
```

## API

coming soon...

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