mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-01-31 13:57:34 +00:00
29 lines
701 B
JavaScript
29 lines
701 B
JavaScript
import React, { createContext, useContext } from 'react';
|
|
import { useWebSocket } from '../utils/websocket';
|
|
|
|
const WebSocketContext = createContext({
|
|
ws: null,
|
|
sendMessage: () => {},
|
|
messages: [],
|
|
isConnected: false
|
|
});
|
|
|
|
export const useWebSocketContext = () => {
|
|
const context = useContext(WebSocketContext);
|
|
if (!context) {
|
|
throw new Error('useWebSocketContext must be used within a WebSocketProvider');
|
|
}
|
|
return context;
|
|
};
|
|
|
|
export const WebSocketProvider = ({ children }) => {
|
|
const webSocketData = useWebSocket();
|
|
|
|
return (
|
|
<WebSocketContext.Provider value={webSocketData}>
|
|
{children}
|
|
</WebSocketContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default WebSocketContext; |