hookagain

hookagain

Hooks

usePhoenixSocket

A hook that provides a phoenix socket.

Installation

npx shadcn@latest add https://hookagain.vercel.app/r/use-phoenix-socket.json

Usage

import { usePhoenixSocket } from "@/hooks/use-phoenix-socket"
 
function Example() {
  const socket = usePhoenixSocket("ws://localhost:4000/socket")
 
  if (!socket) {
    return <div>Connecting to Phoenix server...</div>
  }
 
  return (
    <div>
      <p>Connected to Phoenix server!</p>
      <p>Socket status: {socket.connectionState()}</p>
      <button onClick={() => socket.disconnect()}>
        Disconnect
      </button>
    </div>
  )
}

On this page