Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-socket-hook

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-socket-hook

![GitHub](https://img.shields.io/github/license/leihancn/react-socket-hook) ![David](https://img.shields.io/david/leihancn/react-socket-hook) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/leihancn/react-socket-hook) ![GitH

  • 1.0.1
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

快速启动的脚手架

GitHub David GitHub code size in bytes GitHub release (latest by date) npm type definitions GitHub package.json dynamic

使用
# install
yarn add react-socket-hook
基础用法
import useSocket from 'react-socket-hook'

const { send } = useSocket('wss://echo.websocket.org', {
  onReceived: (data: DataType) => {
    // hanlde data in here.
  },
})

// send some data
send('something')
声明
export declare type DataType = string | ArrayBufferLike | Blob | ArrayBufferView;

export interface UseSocketOptions {
  protocols?: WebSocket['protocol'];
  binaryType?: BinaryType;
  /**
   * 自动连接
   * @default true
   */
  autoConnect?: boolean;
  onConnected?: () => void;
  onClosed?: () => void;
  onReceived?: (data: DataType) => void;
  onError?: (errEvent: Event) => void;
}

export interface UseSocketReturn {
  /**
   * 主动调用来拉起连接。
   * 如果当前已是连接状态,则会保持状态。
   */
  connect: () => void;
  /**
   * 主动断开连接
   */
  close: () => void;
  /**
   * 发送数据
   * @param data
   */
  send: (data: DataType) => Promise<void>;
}

export declare type UseSocket = (url: string, options?: UseSocketOptions) => UseSocketReturn;

常用指令
# 开发
yarn dev
# 打包
yarn build
# 提交代码
yarn cz

Keywords

FAQs

Package last updated on 23 Dec 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc