
Product
Redesigned Repositories Page: A Faster Way to Prioritize Security Risk
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
@lawcket/react-websocket
Advanced tools
A slim Websocket implementation for React 16+. The libray uses the standard browser WebSocket so 'should' be supported in React-Native.
npm install --save @lawcket/react-websocket
or
yarn add @lawcket/react-websocket
Example:
import React, { useState } from 'react';
import Websocket from '@lawcket/react-websocket';
const Messages = () => {
const [messages, addMessage] = useState([]);
return (
<Websocket
url='wss://...'
retry
onOpen={({ send }) => console.log('open')}
onClose={({ code, reason }) => console.log('closed', code, reason)}
onMessage={({ send, data }) => console.log('message', data)}
onError={(error) => console.log('error', error)} >
{({ send, close }) => {
return (
<pre>{JSON.stringify(messages, null, 2)}</pre>
);
}}
</Websocket>
);
}
Name | Type | Description | Default |
---|---|---|---|
url | string | The websocket url to connect to | |
protocol | string | The protocol for the websocket to use | |
retry | boolean | If an error occurs, should it reconnect | true |
onOpen | function | Notifies when the connection has been opened | |
onMessage | function | Notifies when an incoming message has been received | |
onClose | function | Notifies the connection was closed | |
onError | function | Notifies of an error with the connection, will close the connection |
Parameter | Type | Description |
---|---|---|
send | function(any) | A function to send data to the server |
Parameter | Type | Description |
---|---|---|
data | any | Incoming message (usually stringified JSON data) |
send | function(any) | A function to send data to the server |
Parameter | Type | Description |
---|---|---|
error | Error | The error that occured during connection or usage |
Reference: Close codes & reasons
Parameter | Type | Description |
---|---|---|
code | number | The close code sent by the server |
reason | string | The reason the connection was closed |
FAQs
A slim React websocket implementation
The npm package @lawcket/react-websocket receives a total of 10 weekly downloads. As such, @lawcket/react-websocket popularity was classified as not popular.
We found that @lawcket/react-websocket demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Our redesigned Repositories page adds alert severity, filtering, and tabs for faster triage and clearer insights across all your projects.
Security News
Slopsquatting is a new supply chain threat where AI-assisted code generators recommend hallucinated packages that attackers register and weaponize.
Security News
Multiple deserialization flaws in PyTorch Lightning could allow remote code execution when loading untrusted model files, affecting versions up to 2.4.0.