socket.io integration, reload connection list after change

This commit is contained in:
Jan Prochazka
2020-01-04 19:22:57 +01:00
parent 4c52e1eb27
commit 235ef4764b
12 changed files with 501 additions and 26 deletions

View 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);
}