# react-suspense-saga

> redux-saga + react

Latest version **0.1.3** (published 2018-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-suspense-saga
pnpm add react-suspense-saga
yarn add react-suspense-saga
bun add react-suspense-saga
```

## 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.3 |
| Published | 2018-03-18 |
| First published | 2018-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Nick Dujay |
| Maintainers | dat2 |
| Keywords | react, saga |

## Links

- npm: https://www.npmjs.com/package/react-suspense-saga
- Repository: https://github.com/dat2/react-suspense-saga
- Homepage: https://github.com/dat2/react-suspense-saga#readme
- Issues: https://github.com/dat2/react-suspense-saga/issues
- npm.io page: https://npm.io/package/react-suspense-saga

## 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.3 (latest) — 2018-03-18
- 0.1.2 — 2018-03-18
- 0.1.1 — 2018-03-18
- 0.1.0 — 2018-03-18

## README

# Overview
A React component that renders the results of an ES2015 generator.

The *suspense* is killing me, so I decided to explore this before React implements
it themselves!

# Getting started

## Install
```
npm i react-suspense-saga
```
or
```
yarn add react-suspense-saga
```

## Quick Example
```jsx
import runner from 'react-suspense-saga'
import { call, render } from 'react-suspense-saga/effects'

import Api from './Api'

function* greeter() {
  try {
    yield render(
      <p>Loading...</p>
    )
    const user = yield call(Api.fetchUser)
    yield render(
      <p>
        Hello {user.name}!
      </p>
    )
  } catch(e) {
    yield render(
      <p>
        Oh no, something failed!
      </p>
    )
  }
}

export default runner(greeter)
```

# Demos

# API Documentation

## Call
```js
call(
  func: (...args: Array<any>) => Promise<any>,
  ...args: Array<any>
): Effect
```

This will instruct the runner to return the results of the promise back to the
generator when it `resolve`s or `reject`s.

eg.
```jsx
const AsyncGreeting = runner(function*() {
  yield render(<p>Loading...</p>)
  try {
    const response = yield call(fetch, '/api/user')
    const user = yield call(() => response.json())
    yield render(<p>Hello { user.name }!</p>)
  } catch(e) {
    yield render(<p>Something went wrong 🤔</p>)
  }
})
```

## delay
```js
delay(
  ms: number
): Effect
```

This will instruct the runner to use `setTimeout`.

eg.
```jsx
const MyComponent = runner(function*() {
  yield delay(1000)
  yield render(<p>my component</p>)
})
```

## render
```js
render(
  node: React.Node | React.Component,
  extraArgs: Object?
): Effect
```

This will render a node or a react component.

eg.
```jsx
const Loading = () => <p>Loading...</p>

const MyComponent = runner(function*() {
  yield render(Loading) // props for MyComponent will get forwarded to this
  yield render(<p>my component</p>)
})
```

## takeProps
```js
takeProps(): Effect
```

This is a blocking effect, that will not advance the generator until the props
have changed.

You can use this with `redux`, or any component that will change the props like
this:
```js
const AsyncGreeting = runner(function*() {
  // the while true is so that the generator runs forever
  while (true) {
    const { loading, name } = yield takeProps()
    if (loading) {
      yield render(<p>Loading...</p>)
    } else {
      yield render(<p>Hello {name}</p>)
    }
  }
})
```

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