@triggery/socket
Pipe socket.io events or native WebSocket messages into Triggery events. Two hooks, one shape, both StrictMode-safe — useEffect-based attach and detach.
Install
Section titled “Install”pnpm add @triggery/core @triggery/react @triggery/socket npm install @triggery/core @triggery/react @triggery/socket yarn add @triggery/core @triggery/react @triggery/socket bun add @triggery/core @triggery/react @triggery/socket Peer deps: react >= 18.0.0. The native WebSocket constructor is used directly when needed — no extra dependency required.
What’s inside
Section titled “What’s inside”| Export | Purpose |
|---|---|
useSocketIoEvent(trigger, eventName, socket, socketEventName, options?) | Forward a socket.io-client event into a trigger event. Variadic args supported. |
useWebSocketEvent(trigger, eventName, ws, wsEvent, options?) | Forward a native WebSocket event ('message', 'open', 'close', 'error', custom). |
Quick example
Section titled “Quick example”socket.io
Section titled “socket.io”With variadic args:
Native WebSocket
Section titled “Native WebSocket”wsEvent accepts any string — typed for 'message' | 'open' | 'close' | 'error' but extensible.
How it works
Section titled “How it works”Both hooks attach in useEffect (commit phase, StrictMode-safe) and detach on unmount or when their inputs change. If socket / ws is null or undefined, the hook is a no-op until you supply a connection — useful while the socket is being created asynchronously.
Related packages
Section titled “Related packages” @triggery/core Exposes Trigger.
@triggery/react These are React hooks.
@triggery/dom Alternative event source: DOM events, ResizeObserver, IntersectionObserver.
@triggery/query Pair socket-driven events with TanStack Query cache reads.