{"id":15043735,"url":"https://github.com/finneasles/react-io-client","last_synced_at":"2025-03-27T14:18:19.053Z","repository":{"id":65549264,"uuid":"584224529","full_name":"Finneasles/react-io-client","owner":"Finneasles","description":"A socket.io-client hook for react built with Typescript.","archived":false,"fork":false,"pushed_at":"2023-06-14T00:52:51.000Z","size":149,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T14:18:15.471Z","etag":null,"topics":["react-hooks","socket-io","socket-io-client"],"latest_commit_sha":null,"homepage":"https://f1n.dev/react-io-client/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Finneasles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-01T22:37:06.000Z","updated_at":"2023-06-18T22:37:09.000Z","dependencies_parsed_at":"2024-09-25T02:02:07.559Z","dependency_job_id":null,"html_url":"https://github.com/Finneasles/react-io-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finneasles%2Freact-io-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finneasles%2Freact-io-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finneasles%2Freact-io-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Finneasles%2Freact-io-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Finneasles","download_url":"https://codeload.github.com/Finneasles/react-io-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858884,"owners_count":20684062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react-hooks","socket-io","socket-io-client"],"created_at":"2024-09-24T20:49:31.745Z","updated_at":"2025-03-27T14:18:19.024Z","avatar_url":"https://github.com/Finneasles.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-io-client\n\n[![thumbnail](https://repository-images.githubusercontent.com/584224529/39430953-efa7-4b46-b0c7-f89491303b53)](https://i.imgur.com/Ob4qAwu.png)\n\n\u003e Note: The socket connection does not come with any event handlers. Those should be added and managed by the component that use this hook. [More information](https://f1n.dev/react-io-client/).\n\n## Getting Started\n\nInstall dependency:\n\n```bash\nnpm i react-io-client\n```\n\n### Example\n\nHere's an example of how to use the useSocket hook in a React component:\n\n```js\nimport { useSocket } from  \"react-io-client\";\nimport  React, { useEffect, useState } from  \"react\";\n\nexport  default  function  Chat() {\nconst [socket] = useSocket(\"ws://localhost:3000\", { autoConnect:  false });\nconst [messages, setMessages] = useState([]);\n\nuseEffect(() =\u003e {\nif (!socket) return;\nsocket.on(\"message\", (message: string) =\u003e {\nsetMessages((prevMessages) =\u003e [...prevMessages, message]);\n});\nsocket.emit(\"join\", \"room1\");\nreturn () =\u003e {\nsocket.off(\"message\");\nsocket.emit(\"leave\", \"room1\");\n};\n}, [socket]);\n\nreturn messages.map((message, index) =\u003e {\nreturn \u003cdiv  key={index}\u003e{message}\u003c/div\u003e;\n});\n}\n```\n\n## Learn More\n\n* The hook must be wrapped in a useEffect to avoid memory leaks.\n\nYou can learn more in the [Documentation](https://f1n.dev/react-io-client).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinneasles%2Freact-io-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinneasles%2Freact-io-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinneasles%2Freact-io-client/lists"}