The useCrossTab hook provides a synchronized state across multiple tabs (or iframes) of the same origin using the BroadcastChannel API. It works similarly to useSignal, but any changes to the state are broadcasted to all open tabs, ensuring consistent state updates across different browser contexts.
Open second demo page to see state being synchronize across tabs
const count = useCrossTab("counter", 0)
count.value += 1
import { const useCrossTab: <T>(name: string, initialValue: T) => Signal<T>
useCrossTab } from "@kaioken-core/hooks"
const const count: Signal<number>
count = useCrossTab<number>(name: string, initialValue: number): Signal<number>
useCrossTab("counter", 0)
const count: Signal<number>
count.Signal<number>.value: number
value += 1