mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 12:35:59 +00:00
socket.io integration, reload connection list after change
This commit is contained in:
18
web/src/utility/SocketProvider.js
Normal file
18
web/src/utility/SocketProvider.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import io from 'socket.io-client';
|
||||
import React from 'react';
|
||||
|
||||
const SocketContext = React.createContext();
|
||||
|
||||
export function SocketProvider({ children }) {
|
||||
const [socket, setSocket] = React.useState();
|
||||
React.useEffect(() => {
|
||||
// const newSocket = io('http://localhost:3000', { transports: ['websocket'] });
|
||||
const newSocket = io('http://localhost:3000');
|
||||
setSocket(newSocket);
|
||||
}, []);
|
||||
return <SocketContext.Provider value={socket}>{children}</SocketContext.Provider>;
|
||||
}
|
||||
|
||||
export default function useSocket() {
|
||||
return React.useContext(SocketContext);
|
||||
}
|
||||
Reference in New Issue
Block a user