# reez

> Handling async action with ease

Latest version **0.0.7** (published 2021-08-09) · ISC license · 0 weekly downloads

## Install

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

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2021-08-09 |
| First published | 2021-07-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 85.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | linq2js |
| Maintainers | linq2js |
| Keywords | state-manager, state-management, store, flux, action, async, async-dispatching, async-action, dispatching, action-call, cache, remote |

## Links

- npm: https://www.npmjs.com/package/reez
- Homepage: https://github.com/linq2js/reez#readme
- Issues: https://github.com/linq2js/reez/issues
- npm.io page: https://npm.io/package/reez

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 0.0.7 (latest) — 2021-08-09
- 0.0.6 — 2021-08-08
- 0.0.5 — 2021-08-08
- 0.0.4 — 2021-08-07
- 0.0.3 — 2021-07-26
- 0.0.1 — 2021-07-26
- 0.0.0 — 2021-07-22

## README

# REEZ

Handling async action with ease

## Installation

```bash
$ npm i reez --save
# or
$ yarn add reez
```

## Features

- Simple API
- Request caching and deduping supported
- Auto polling supported
- ErrorBoundary and Suspense supported
- Optimistic updating supported
- Prefetching/debouncing/throttling supported
- Garbage collection supported

## Getting started

```jsx
import { useAsync } from "reez";

function App() {
  // create async dispatcher
  const dispatcher = useAsync(
    // cache key
    "repoData",
    // async action
    () =>
      fetch("https://api.github.com/repos/facebook/react").then((res) =>
        res.json()
      )
  );
  // dispatch and retrive async result
  const result = dispatcher();

  // show loading status
  if (result.loading) {
    return <div>Loading...</div>;
  }

  // request fail
  if (result.fail) {
    return <div>Error: {result.error.message}</div>;
  }
  // request success
  const data = result.data;
  return (
    <div>
      <h1>{data.name}</h1>
      <p>{data.description}</p>
      <strong>👀 {data.subscribers_count}</strong>{" "}
      <strong>✨ {data.stargazers_count}</strong>{" "}
      <strong>🍴 {data.forks_count}</strong>
    </div>
  );
}
```

## Examples

### Mutating async result locally

```jsx
function App() {
  // create async dispatcher
  const result = useAsync(
    // cache key
    "repoData",
    // async action
    () =>
      fetch("https://api.github.com/repos/facebook/react").then((res) =>
        res.json()
      )
  ).call();

  if (result.loading) return "Loading...";
  const data = result.data;

  function handleClick() {
    result.data = {
      ...data,
      name: prompt("Enter new repo name", data.name),
    };
  }

  return (
    <div>
      <h1>{data.name}</h1>
      <button onClick={handleClick}>Change repo name</button>
    </div>
  );
}
```

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