import React, { useReducer } from "react"; import { createSocketIoContext } from "../../socketio"; import { Chat, ChatCallbacksNames, ChatOperationsNames, JobType, } from "./services/hub"; const SocketContext = createSocketIoContext({ shareConnectionBetweenTab: true, }); const Socket = () => { return ( token} // dependencies={[token]} //remove previous connection and create a new connection if changed url={"http://127.0.0.1:4001"} > ); }; function Todo() { const [list, setList] = useReducer((state: string[] = [], action: string) => { return [action, ...state].slice(0, 200); }, []); SocketContext.useSocketEffect( ChatCallbacksNames.startwork, // eslint-disable-next-line @typescript-eslint/no-empty-function (message) => { setList("⬇ :" + JSON.stringify(message)); }, [], ); SocketContext.useSocketEffect( ChatCallbacksNames.hello, (message) => { setList("⬇ :" + JSON.stringify(message)); }, [], ); return (

React socket.io

{list.map((message, index) => (

{message}

))}
); } export { Socket };