jarvis/dewey/hooks/useSocket.ts

14 lines
325 B
TypeScript
Raw Normal View History

2024-10-01 19:31:57 -04:00
import { useEffect, useState } from 'react'
import io from 'socket.io-client'
export default function useSocket() {
const [socket, setSocket] = useState<any>(null)
useEffect(() => {
const newSocket = io('http://localhost:5001')
setSocket(newSocket)
return () => newSocket.close()
}, [])
return socket
}