{"id":13731958,"url":"https://github.com/mehmetkose/react-websocket","last_synced_at":"2025-05-15T17:07:42.508Z","repository":{"id":35622723,"uuid":"39896550","full_name":"mehmetkose/react-websocket","owner":"mehmetkose","description":"Easy-to-use React component for websocket communications.","archived":false,"fork":false,"pushed_at":"2022-03-10T19:34:04.000Z","size":1309,"stargazers_count":349,"open_issues_count":16,"forks_count":81,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-10T18:48:22.541Z","etag":null,"topics":["react","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mehmetkose.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}},"created_at":"2015-07-29T14:02:29.000Z","updated_at":"2025-04-28T01:54:36.000Z","dependencies_parsed_at":"2022-08-17T21:55:13.340Z","dependency_job_id":null,"html_url":"https://github.com/mehmetkose/react-websocket","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehmetkose%2Freact-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehmetkose%2Freact-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehmetkose%2Freact-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehmetkose%2Freact-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehmetkose","download_url":"https://codeload.github.com/mehmetkose/react-websocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"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","websocket"],"created_at":"2024-08-03T02:01:42.522Z","updated_at":"2025-05-15T17:07:37.500Z","avatar_url":"https://github.com/mehmetkose.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# react-websocket [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/mehmetkose/react-websocket/edit/master/README.md) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmehmetkose%2Freact-websocket.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmehmetkose%2Freact-websocket?ref=badge_shield)\n\n`react-websocket` is a easy-to-use React component for websocket communications.\n\n## Help Wanted\n\nThings here are running very slowly as I have a lot of other stuff to take care at the moment so please don't be upset if I don't answer your question or if a PR sits unreviewed for a few days or weeks. Anyone interested in helping it move faster can help by submitting or reviewing PR's and answering each other's questions.\n\n\n### Installing\n\n```\nnpm install --save react-websocket\n```\n\n### Usage\n\n```js\n  import React from 'react';\n  import Websocket from 'react-websocket';\n\n  class ProductDetail extends React.Component {\n\n    constructor(props) {\n      super(props);\n      this.state = {\n        count: 90\n      };\n    }\n\n    handleData(data) {\n      let result = JSON.parse(data);\n      this.setState({count: this.state.count + result.movement});\n    }\n\n    render() {\n      return (\n        \u003cdiv\u003e\n          Count: \u003cstrong\u003e{this.state.count}\u003c/strong\u003e\n\n          \u003cWebsocket url='ws://localhost:8888/live/product/12345/'\n              onMessage={this.handleData.bind(this)}/\u003e\n        \u003c/div\u003e\n      );\n    }\n  }\n\n  export default ProductDetail;\n```\n\n### Properties\n\n#### url\n\n**required**\nThe url the websocket connection is listening to.\n\n#### onMessage\n\n**required**\nThe callback called when data is received. Data is `JSON.parse`'d\n\n#### onOpen\n\nThe callback called when the connection is successfully opened.\n\n#### onClose\n\nThe callback called when the connection is closed either due to server disconnect or network error.\n\n#### debug\n\ndefault: **false**\nSet to **true** to see console logging\n\n#### reconnect\n\ndefault: **true**\n\naccelerated reconnection time\n\n\n## License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmehmetkose%2Freact-websocket.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmehmetkose%2Freact-websocket?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehmetkose%2Freact-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehmetkose%2Freact-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehmetkose%2Freact-websocket/lists"}