{"id":17831221,"url":"https://github.com/dnamsons/rails-hooks","last_synced_at":"2026-05-18T15:11:19.026Z","repository":{"id":143511597,"uuid":"340919219","full_name":"dnamsons/rails-hooks","owner":"dnamsons","description":"Rails javascript APIs turned into Hooks for use in functional React components","archived":false,"fork":false,"pushed_at":"2021-02-21T15:07:37.000Z","size":6,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T03:23:41.391Z","etag":null,"topics":["actioncable","rails"],"latest_commit_sha":null,"homepage":"","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/dnamsons.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":"2021-02-21T14:20:45.000Z","updated_at":"2021-02-21T15:07:38.000Z","dependencies_parsed_at":"2023-07-01T22:33:23.723Z","dependency_job_id":null,"html_url":"https://github.com/dnamsons/rails-hooks","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/dnamsons%2Frails-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnamsons%2Frails-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnamsons%2Frails-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnamsons%2Frails-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnamsons","download_url":"https://codeload.github.com/dnamsons/rails-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246811312,"owners_count":20837753,"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":["actioncable","rails"],"created_at":"2024-10-27T19:42:29.189Z","updated_at":"2026-05-18T15:11:14.003Z","avatar_url":"https://github.com/dnamsons.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rails hooks\n\n[![Version][version-badge]][package]\n\n## Installation\n\nwith npm\n\n```sh\nnpm install rails-hooks\n```\n\nwith yarn\n\n```sh\nyarn add rails-hooks\n```\n\n## API\n\n- [useCable](#usecable)\n\n### `useCable`\n\nRequires for `CableProvider` to be set somewhere above the component where `useCable` will be used.\n\n```tsx\nimport React from 'react'\nimport { CableProvider } from 'rails-hooks'\nimport { createConsumer } = '@rails/actioncable'\n\nconst App = () =\u003e {\n  const consumer = createConsumer('optional-url.com')\n\n  return(\n    \u003cCableProvider consumer={consumer}\u003e\n      ...\n    \u003c/CableProvider\u003e\n  )\n}\n```\n\nThen `useCable` can be used like this:\n\n```tsx\nimport { useCable } from 'rails-hooks'\n\nconst [messages, setMessages] = useState([])\n\nconst chatChannel = useCable(\n  { channel: 'ChatChannel', room: 'Best room' },\n  {\n    received(data) {\n      setMessages(prevMessages =\u003e [...prevMessages, data])\n    },\n  }\n)\n\nchatChannel.send({ sent_by: 'Paul', body: 'This is a cool chat app.' })\n```\n\n[version-badge]: https://img.shields.io/npm/v/rails-hooks.svg?style=flat-square\n[package]: https://www.npmjs.com/package/rails-hooks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnamsons%2Frails-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnamsons%2Frails-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnamsons%2Frails-hooks/lists"}