Spaces:
Paused
Paused
Download client/src/hooks/useSocket.jsx from arabdullah/chatty: direct link, hf CLI and curl.
- Browser
- Download file 452 Bytes
-
https://huggingface.co/spaces/arabdullah/chatty/resolve/main/client/src/hooks/useSocket.jsx
- Command line
-
hf download hf://spaces/arabdullah/chatty/client/src/hooks/useSocket.jsx
-
curl -L -o useSocket.jsx https://huggingface.co/spaces/arabdullah/chatty/resolve/main/client/src/hooks/useSocket.jsx
452 Bytes
| import { useSelector } from "react-redux"; | |
| import { io } from "socket.io-client"; | |
| const socket = io(); | |
| const useSocket = () => { | |
| const userId = useSelector((state) => state.userReducer.user._id); | |
| const socketEmit = (action, payload, fn) => { | |
| socket.emit(action, payload, fn); | |
| }; | |
| const socketListen = (action, fn) => { | |
| socket.on(action, fn); | |
| }; | |
| return { socketEmit, socketListen, userId, socket }; | |
| }; | |
| export default useSocket; | |