{"id":17888083,"url":"https://github.com/soywod/react-captain","last_synced_at":"2025-07-24T03:06:25.921Z","repository":{"id":37883953,"uuid":"173100084","full_name":"soywod/react-captain","owner":"soywod","description":":anchor: A collection of strongly typed React hooks and contexts.","archived":false,"fork":false,"pushed_at":"2023-01-07T16:05:25.000Z","size":1710,"stargazers_count":16,"open_issues_count":17,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T02:26:22.560Z","etag":null,"topics":["collection","react","react-context","react-hooks","reactjs","typescript"],"latest_commit_sha":null,"homepage":"https://react-captain.soywod.me","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/soywod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"soywod","open_collective":"soywod","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-02-28T11:29:21.000Z","updated_at":"2022-07-11T18:52:43.000Z","dependencies_parsed_at":"2023-02-07T14:47:15.650Z","dependency_job_id":null,"html_url":"https://github.com/soywod/react-captain","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/soywod/react-captain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-captain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-captain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-captain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-captain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soywod","download_url":"https://codeload.github.com/soywod/react-captain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-captain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266786798,"owners_count":23983871,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["collection","react","react-context","react-hooks","reactjs","typescript"],"created_at":"2024-10-28T13:36:31.173Z","updated_at":"2025-07-24T03:06:25.892Z","avatar_url":"https://github.com/soywod.png","language":"TypeScript","funding_links":["https://patreon.com/soywod","https://opencollective.com/soywod"],"categories":[],"sub_categories":[],"readme":"# :anchor: React Captain [![Build Status](https://travis-ci.org/soywod/react-captain.svg?branch=master)](https://travis-ci.org/soywod/react-captain) [![codecov](https://codecov.io/gh/soywod/react-captain/branch/master/graph/badge.svg)](https://codecov.io/gh/soywod/react-captain) [![npm](https://img.shields.io/npm/v/react-captain?label=npm)](https://www.npmjs.com/package/react-captain)\n\nA collection of strongly typed React hooks and contexts.\n\n*Live demo at https://react-captain.soywod.me.*\n\n## Table of contents\n\n  - [Installation](#installation)\n  - [Examples](#examples)\n    - [Click outside](#click-outside)\n    - [Debounce](#debounce)\n    - [Timeout](#timeout)\n    - [Interval](#interval)\n    - [Stored state](#stored-state)\n    - [Toggle](#toggle)\n    - [Subject](#subject)\n    - [Behavior subject](#behavior-subject)\n  - [Development](#development)\n  - [Tests](#tests)\n    - [Unit tests](#unit-tests)\n    - [End-to-end tests](#end-to-end-tests)\n  - [Changelog](#changelog)\n  - [License](#license)\n\n## Installation\n\n```bash\nyarn add react-captain\n# or\nnpm install react-captain\n```\n\n## Examples\n\n*Live demo at https://react-captain.soywod.me.*\n\n### [Click outside](https://github.com/soywod/react-captain/tree/master/src/click-outside)\n\nCapture click event outside of the given HTMLElement.\n\n```typescript\nimport {useClickOutside} from \"react-captain\"\n\nconst Component: FC = () =\u003e {\n  const ref = useRef\u003cHTMLDivElement | null\u003e(null)\n  useClickOutside(ref, () =\u003e console.log(\"Clicked outside!\"))\n\n  return (\n    \u003cdiv ref={ref}\u003e\n      Click outside\n    \u003c/div\u003e\n  )\n}\n```\n\n### [Debounce](https://github.com/soywod/react-captain/tree/master/src/debounce)\n\nAdd debounce to a handler.\n\n```typescript\nimport {useDebounce} from \"react-captain\"\n\nfunction Component() {\n  const handler = useDebounce(() =\u003e console.log(\"Hello!\"), 1000)\n\n  return (\n    \u003c\u003e\n      \u003cbutton onClick={handler}\u003e\n        Say hello with delay\n      \u003c/button\u003e\n      \u003cbutton onClick={handler.abort}\u003e\n        Abort\n      \u003c/button\u003e\n      \u003cbutton onClick={handler.terminate}\u003e\n        Terminate\n      \u003c/button\u003e\n    \u003c/\u003e\n  )\n}\n```\n\n### [Timeout](https://github.com/soywod/react-captain/tree/master/src/timeout)\n\nA wrapper around `setTimeout`.\n\n```typescript\nimport {useTimeout} from \"react-captain\"\n\nfunction Component() {\n  const handler = useTimeout(() =\u003e console.log(\"Hello!\"), 1000)\n\n  return (\n    \u003c\u003e\n      \u003cbutton onClick={handler}\u003e\n        Say hello with delay\n      \u003c/button\u003e\n      \u003cbutton onClick={handler.abort}\u003e\n        Abort\n      \u003c/button\u003e\n      \u003cbutton onClick={handler.terminate}\u003e\n        Terminate\n      \u003c/button\u003e\n    \u003c/\u003e\n  )\n}\n```\n\n### [Interval](https://github.com/soywod/react-captain/tree/master/src/interval)\n\nA wrapper around `setInterval`, using [toggle](#toggle).\n\n```typescript\nimport {useInterval} from \"react-captain\"\n\nfunction Component() {\n  const [isOn, toggle] = useInterval(() =\u003e console.log(\"Hello!\"))\n\n  return (\n    \u003cbutton onClick={handler}\u003e\n      {isOn ? \"Stop\" : \"Say hello\"}\n    \u003c/button\u003e\n  )\n}\n```\n\n### [Stored state](https://github.com/soywod/react-captain/tree/master/src/stored-state)\n\nA persistant useState, based on React's `useState` and\n[localForage](https://github.com/localForage/localForage). Drivers supported:\nlocalStorage, WebSQL and IndexedDB.\n\n```typescript\nimport {useStoredState} from \"react-captain\"\n\nfunction Component() {\n  const [value, setValue] = useStoredState(\"storage-key\", \"Default value\")\n\n  return (\n    \u003cbutton onClick={() =\u003e setValue(\"Value changed!\")}\u003e\n      {String(value)}\n    \u003c/button\u003e\n  )\n}\n```\n\n### [Toggle](https://github.com/soywod/react-captain/tree/master/src/toggle)\n\nA `useState` for booleans.\n\n```typescript\nimport {useToggle} from \"react-captain\"\n\nconst Component: FC = () =\u003e {\n  const [isOn, toggle] = useToggle(false)\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton onClick={toggle}\u003e\n        Switch status: {isOn ? \"ON\" : \"OFF\"}\n      \u003c/button\u003e\n      \u003cbutton onClick={() =\u003e toggle(false)}\u003e\n        Reset toggle\n      \u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n### [Subject](https://github.com/soywod/react-captain/tree/master/src/subject)\n\nA wrapper around\n[`rxjs.Subject`](https://www.learnrxjs.io/learn-rxjs/subjects/subject).\n\n```typescript\nimport {useSubject} from \"react-captain\"\nimport {Subject} from \"rxjs\"\n\nconst subject$ = new Subject\u003cnumber\u003e()\n\nconst Component: FC = () =\u003e {\n  const [counter, setCounter] = useState(0)\n  useSubject(subject$, setCounter)\n  return \u003cbutton onClick={() =\u003e subject$(counter + 1)}\u003e{counter}\u003c/button\u003e\n}\n```\n\n### [Behavior subject](https://github.com/soywod/react-captain/tree/master/src/behavior-subject)\n\nA wrapper around\n[`rxjs.BehaviorSubject`](https://www.learnrxjs.io/learn-rxjs/subjects/behaviorsubject).\n\n```typescript\nimport {useBehaviorSubject} from \"react-captain\"\nimport {BehaviorSubject} from \"rxjs\"\n\nconst subject$ = new BehaviorSubject(0)\n\nconst Component: FC = () =\u003e {\n  const [counter, setCounter] = useBehaviorSubject(subject$, counter =\u003e {\n    console.log(\"New counter received:\", counter)\n  })\n\n  return \u003cbutton onClick={() =\u003e setCounter(counter + 1)}\u003e{counter}\u003c/button\u003e\n}\n```\n## Development\n\n```bash\ngit clone https://github.com/soywod/react-captain.git\ncd react-captain\nyarn install\n```\n\nTo start the development server:\n\n```bash\nyarn start\n```\n\nTo build the lib:\n\n```bash\nyarn build\n```\n\nTo build the demo:\n\n```bash\nyarn build:demo\n```\n\n## Tests\n### Unit tests\n\nUnit tests are handled by [Jest](https://jestjs.io) (`.test` files) and [React\nTesting Library](https://testing-library.com/docs/react-testing-library/intro)\n(`.spec` files).\n\n```bash\nyarn test:unit\n```\n\n### End-to-end tests\n\nEnd-to-end tests are handled by [Cypress](https://www.cypress.io) (`.e2e`\nfiles).\n\n```bash\nyarn start\nyarn test:e2e\n```\n\n## Changelog\n\nSee [CHANGELOG.md](https://github.com/soywod/react-captain/blob/master/CHANGELOG.md).\n\n## License\n\n[MIT](https://github.com/soywod/react-captain/blob/master/LICENSE) -\nCopyright © 2019-2020 soywod.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoywod%2Freact-captain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoywod%2Freact-captain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoywod%2Freact-captain/lists"}