You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-signalr

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-signalr

React-signalr is a tools for using signalr web socket in react/react-native apps

0.2.17
Source
npmnpm
Version published
Weekly downloads
7.2K
8.79%
Maintainers
1
Weekly downloads
 
Created
Source

React-Signalr

NPM

install size dependencies

React-Signalr Is a tools for using signalR, Socket.io or WebSocket in react/react-native apps

  • Supported microsoft/signalR version 5 and later
  • Supported Socket.io
  • Supported WebSocket

Features

  • Hooks for connect event to a component
  • Manage connections in multiple tabs (SignalR can only have about 6 tabs open). React-signalr will create a connection open and send event to other tabs by hermes-channel
  • Handle reconnect

TOC

install

$ yarn add react-signalr

getStart

import {
  createSignalRContext, // SignalR
  createWebSocketContext, // WebSocket
  createSocketIoContext, // Socket.io
} from "react-signalr";

create a signalr context,

import { createSignalRContext } from "react-signalr";

const { useSignalREffect, Provider } = createSignalRContext();
// or createSocketIoContext() for socket.io

const App = () => {
  const { token } = YourAccessToken;

  return (
    <SignalRContext.Provider
      connectEnabled={!!token}
      accessTokenFactory={() => token}
      dependencies={[token]} //remove previous connection and create a new connection if changed
      url={"https://example/hub"}
    >
      <Routes />
    </SignalRContext.Provider>
  );
};

useSignalREffect

Use this to connect to an event

const { useSignalREffect, Provider } = createSignalRContext();

const Comp = () => {
  const [messages, setMessage] = useState([]);

  useSignalREffect(
    "event name",
    (message) => {
      setMessage([...messages, message]);
    },
    [messages],
  );

  return null;
};

React-Native

Full supported

Keywords

react-signalr

FAQs

Package last updated on 25 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts