Gives components the server's live updates. Each hook reads one of the contexts WSProvider fills, so that a component re-renders only with the part it uses. Outside WSProvider, they return inert defaults.

Functions

f
useOnReconnect(callback: () => void): void

Calls callback after each reconnection of the socket, never on the first connection, for the component to fetch again what it may have missed while the socket was down. The live lists and pages use it.

f
useWS(): WSContextValue

Returns the connection's status, the live votes, likes, new and deleted dumps and playlists, the unread count, and the functions that vote and like. A component using it re-renders on every change to any of them.

f
useWSChat(): WSChatContextValue

Returns the chat's messages, typing and read state. A component using it re-renders with every message and typing change, so a component that needs only the unread count still pays for them.

f
useWSEvent<K extends keyof WSEvents>(
kind: K,
handler: (event: WSEvents[K]) => void
): void

Calls handler with every event of kind the socket brings, as it arrives, for as long as the component is mounted. The handler applies it to what the component fetched, through state setters: it runs outside render, and always as the latest render defined it. The list sync hooks, the dump and playlist pages, the profile, the bell and the categories use it.

f
useWSPresence(): WSPresenceContextValue

Returns who is online, for the presence row.