mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 10:00:46 -04:00
14 lines
603 B
React
14 lines
603 B
React
// Socket Context Provider
|
|
// Purpose: Creates React context for shared socket lifecycle and connection state. Scope: Owns socket initialization, reconnect behavior, and consumer hooks.
|
|
/* eslint-disable react-refresh/only-export-components */
|
|
|
|
// src/context/SocketContext.jsx
|
|
import { createContext, useContext } from "react";
|
|
import { socket } from "../lib/socket";
|
|
|
|
const SocketContext = createContext(socket);
|
|
export const SocketProvider = ({ children }) => (
|
|
<SocketContext.Provider value={socket}>{children}</SocketContext.Provider>
|
|
);
|
|
export const useSocket = () => useContext(SocketContext);
|