mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
20 lines
523 B
JavaScript
20 lines
523 B
JavaScript
import { createContext, useContext } from "react"
|
|
import { io } from "socket.io-client"
|
|
import { WEBSOCKET_PUBLIC_URL } from "../../config.mjs"
|
|
|
|
export const socket = io(WEBSOCKET_PUBLIC_URL, {
|
|
transports: ["websocket"],
|
|
})
|
|
|
|
export const SocketContext = createContext()
|
|
|
|
export const SocketContextProvider = ({ children }) => (
|
|
<SocketContext.Provider value={socket}>{children}</SocketContext.Provider>
|
|
)
|
|
|
|
export function useSocketContext() {
|
|
const context = useContext(SocketContext)
|
|
|
|
return { socket: context }
|
|
}
|