0.7.0 • Published 5 years ago

react-socket-hooks v0.7.0

Weekly downloads
44
License
MIT
Repository
github
Last release
5 years ago

React Socket Hooks

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

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:

yarn add react-socket-hooks

or if Yarn isn't your thing:

npm install react-socket-hooks --save

This library makes use of and assumes the WebSocket API 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:

yarn
yarn lint
yarn test
yarn compile
0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago