Skip to content

Instantly share code, notes, and snippets.

View Vibeesarma's full-sized avatar
🥶
Coding....

Vibeesarma Vibeesarma

🥶
Coding....
View GitHub Profile
@Vibeesarma
Vibeesarma / useBroadcastChannel.ts
Created February 6, 2024 03:53 — forked from KristofferEriksson/useBroadcastChannel.ts
A React hook that allows you to send and receive messages between browser tabs or windows
import { useCallback, useEffect, useRef, useState } from "react";
interface UseBroadcastChannelOptions {
name: string;
onMessage?: (event: MessageEvent) => void;
onMessageError?: (event: MessageEvent) => void;
}
interface UseBroadcastChannelReturn<D, P> {
isSupported: boolean;