Socket
Socket
Sign inDemoInstall

use-broadcast-ts

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-broadcast-ts

Use the Broadcast Channel API in React easily with hooks and Typescript!


Version published
Weekly downloads
3.2K
increased by2.66%
Maintainers
1
Weekly downloads
 
Created
Source

use-wasm-ts

Version GitHub Workflow Status (with branch) GitHub

Use the Broadcast Channel API in React easily with hooks and Typescript!

npm install use-broadcast-ts

This package allows you to use the Broadcast API with a simple hook.

Usage

import { FC } from 'react';
import { useBroadcast } from 'use-broadcast-ts';

const MyComponent: FC = () => {
    const {
        state,
        send,
    } = useBroadcast<{ value: number }>('my-channel', {value: 0})

    return (
        <>
            <p>My value is: {state.value}</p>
            <button onClick={() => send({value: 10})}/>
        </>
    );
};

export default MyComponent;

API

useBroadcast

useWasm<T>(name: string, value?: T): {
    state: T;
    send: (value: T) => void;
};
Parameters
name

Type: string

The name of the channel to use.

value

Type: T (default: undefined)

The initial value of the channel.

Return
state

Type: T

The current value of the channel.

send

Type: (value: T) => void

Send a new value to the channel.

What data can I send?

You can send any of the supported types by the structured clone algorithm like :

  • String
  • Boolean
  • Number
  • Array
  • Object
  • Date
  • ...

In short, you cannot send :

  • Function
  • Dom Element
  • And some other types

See the MDN documentation for more information.

License

MIT

Keywords

FAQs

Package last updated on 23 May 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

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