# state-streamer

> Stream data to react components

Latest version **0.2.2** (published 2021-10-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install state-streamer
pnpm add state-streamer
yarn add state-streamer
bun add state-streamer
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2021-10-22 |
| First published | 2021-07-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Laurent Zuijdwijk |
| Maintainers | laurent.zuijdwijk |
| Keywords | react, state, streams, reactive, observable, hooks |

## Links

- npm: https://www.npmjs.com/package/state-streamer
- npm.io page: https://npm.io/package/state-streamer

## Dependencies (1)

- [highland](https://npm.io/package/highland.md) ^2.13.5

## 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.2.2 (latest) — 2021-10-22
- 0.2.1 — 2021-10-20
- 0.2.0 — 2021-10-20
- 0.1.1 — 2021-10-06
- 0.1.0 — 2021-07-04

## README

[![CircleCI](https://circleci.com/gh/LaurentZuijdwijk/react-use-data-stream-hook/tree/master.svg?style=svg)](https://circleci.com/gh/LaurentZuijdwijk/react-use-data-stream-hook/tree/master)

# Data streamer framework

Easy to create service layer and data streaming for React applications.

Here is an example service layer to retrieve and add todos.

```javascript

import { BaseService } from "streamer";

class TodoService extends BaseService {
  constructor(){
      this.todos = []
  }
  getTodos() {
    const subscription = this.subscribe(subject);
    this.write({loading:true})
    fetch('https://catfact.ninja/fact').then((response)=>{
      return response.json();

    }).then(fact => {
      this.write(subject, {...fact, loading: false });
  })
    return subscription;
  }
  addTodo(todo){
    this.todos.push(todo);
    this.write('allTodos', this.todos);
  }
}
```

Note that in the example above we return a `Subscription`, this allows us to use the provided hook like so

```javascript
import { useStreamer } from "streamer";

export default (props) => {
    const { payload } = useStreamer(factService.subscribeToFacts, 'cats');
    if(payload && payload.loading){
        return <span>Loading...</span>
    }

    if(payload && payload.fact){
        return <div>
            <span>{payload.fact}</span><br />
        </div>;
    }
    else return <></>
}
```

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