# react-socket-hooks

> A set of react hooks to work real nice with the WebSocket API

Latest version **0.7.0** (published 2019-07-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-socket-hooks
pnpm add react-socket-hooks
yarn add react-socket-hooks
bun add react-socket-hooks
```

## 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.7.0 |
| Published | 2019-07-01 |
| First published | 2019-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 8.0 |
| Dependencies | 0 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Archon Information Systems |
| Maintainers | mdarens |
| Keywords | react, hooks, socket, websocket |

## Links

- npm: https://www.npmjs.com/package/react-socket-hooks
- Repository: https://github.com/civicsource/react-socket-hooks
- Homepage: https://github.com/civicsource/react-socket-hooks#readme
- Issues: https://github.com/civicsource/react-socket-hooks/issues
- npm.io page: https://npm.io/package/react-socket-hooks

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2019-07-01
- 0.6.1 — 2019-07-01
- 0.6.0 — 2019-06-28
- 0.5.1 — 2019-04-25
- 0.5.0 — 2019-04-25
- 0.4.3 — 2019-04-24
- 0.4.2 — 2019-04-23
- 0.4.1 — 2019-04-23
- 0.4.0 — 2019-04-16
- 0.3.0 — 2019-04-09
- 0.2.0 — 2019-04-09
- 0.1.0 — 2019-04-05

## README

# React Socket Hooks

> A set of react hooks to work real nice with the WebSocket API.

```js
import { useCallback } from "react";
import useSocket from "react-socket-hooks";

const mySocketMessageHandler1 = useCallback(msg => console.log(msg), []);
const mySocketMessageHandler2 = useCallback(msg => console.log("ohmy", msg), []);

const { useMessageHandler, send } = useSocket("wss://example.com");
useMessageHandler(mySocketMessageHandler1);
useMessageHandler(mySocketMessageHandler2);

// …later, perhaps in response to a user action
send("hello, server");
```

Install with [Yarn](https://yarnpkg.com/en/):

```shell
yarn add react-socket-hooks
```

or if Yarn isn't your thing:

```shell
npm install react-socket-hooks --save
```

This library makes use of and assumes the [`WebSocket` API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) is available on the global scope. You will need to polyfill it if it is not available in the current environment.

## Build/Run Locally

After cloning this repo, run:

```shell
yarn
yarn lint
yarn test
yarn compile
```

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