{"id":20557266,"url":"https://github.com/nodecg/react-hooks","last_synced_at":"2025-04-14T13:20:40.213Z","repository":{"id":33503745,"uuid":"158957058","full_name":"nodecg/react-hooks","owner":"nodecg","description":"React Custom Hooks for NodeCG","archived":false,"fork":false,"pushed_at":"2024-12-26T23:30:21.000Z","size":1364,"stargazers_count":23,"open_issues_count":0,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T09:55:56.994Z","etag":null,"topics":["custom-hook","nodecg","react","react-hooks","typescript"],"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/nodecg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-11-24T17:05:53.000Z","updated_at":"2025-04-03T00:02:19.000Z","dependencies_parsed_at":"2024-01-01T10:04:43.045Z","dependency_job_id":"e7c56990-f1b5-4ea4-bd0d-6f4f18c75f29","html_url":"https://github.com/nodecg/react-hooks","commit_stats":null,"previous_names":["nodecg/use-nodecg","hoishin/use-nodecg","nodecg/react-hooks"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecg%2Freact-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecg%2Freact-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecg%2Freact-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecg%2Freact-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodecg","download_url":"https://codeload.github.com/nodecg/react-hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886334,"owners_count":21177645,"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":["custom-hook","nodecg","react","react-hooks","typescript"],"created_at":"2024-11-16T03:35:58.934Z","updated_at":"2025-04-14T13:20:40.180Z","avatar_url":"https://github.com/nodecg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @nodecg/react-hooks\n\nThis package is a collection custom hooks of [React Hooks](https://reactjs.org/docs/hooks-intro.html) for NodeCG API.\n\n🚨 This package is in alpha state. But feel free to try out and file an issue for suggestion/bugs!\n\n## Install\n\n```sh\nnpm install @nodecg/react-hooks\n# or\nyarn add @nodecg/react-hooks\n# or\npnpm add @nodecg/react-hooks\n```\n\n## About React Hooks\n\n(This section comes from when React hooks was just introduced as an alpha feature, but is still useful to keep as an introduction.)\n\nThe React Hooks are a new way of **sharing code** between components, introduced in version 16.8.\n\n**_Please read the documentation of React Hooks thoroughly before using them._**\n\n- [Video introduction](https://youtu.be/dpw9EHDh2bM)\n- [The Motivation](https://reactjs.org/docs/hooks-intro.html#motivation)\n- [Rules](https://reactjs.org/docs/hooks-rules.html)\n- [Hooks API reference](https://reactjs.org/docs/hooks-reference.html)\n- [FAQ](https://reactjs.org/docs/hooks-faq.html)\n\nIt also helps to learn the background mechanism of React Hooks.\n[React hooks: not magic, just arrays](https://medium.com/@ryardley/react-hooks-not-magic-just-arrays-cd4f1857236e)\n\n## Recommendation\n\nUse [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks) in your project. It is 100% smarter than you to detect violation of the Rules of Hooks.\n\n## Usage\n\n### `useReplicant`\n\n- Subscribes to specified replicant and returns the value as state.\n- Allows you to use replicant values in function component.\n\n```tsx\nimport { useReplicant } from \"@nodecg/react-hooks\";\n\n// This component will re-render when the `counter replicant value changes\nexport function RunnerName() {\n  const [count, setCount] = useReplicant(\"counter\");\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003e{count}\u003c/div\u003e\n      \u003cbutton onClick={() =\u003e setCount(count + 1)} /\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### `useListenFor`\n\n- Subscribes messages with `listenFor`, and unlistens on unmount.\n- Combining with other hooks enables powerful stateful features with function component\n\n```tsx\nimport { useListenFor } from \"@nodecg/react-hooks\";\n\n// Shows modal for 1 second when NodeCG receives 'errorHappened' message from the server\nexport function AlertOnMessage() {\n  const [showAlert, setShowAlert] = useState(false);\n  useListenFor(\"errorHappened\", () =\u003e {\n    setShowAlert(true);\n  });\n  useEffect(() =\u003e {\n    if (!showAlert) {\n      return;\n    }\n    // Disappear alert 1 second after\n    const timer = setTimeout(() =\u003e {\n      setShowAlert(false);\n    }, 1000);\n    // Make sure to return cleanup function\n    return () =\u003e {\n      clearTimeout(timer);\n    };\n  }, [showAlert]);\n\n  return \u003cModal show={showAlert} /\u003e;\n}\n```\n\n## License\n\nMIT \u0026copy; Keiichiro Amemiya (Hoishin)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecg%2Freact-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodecg%2Freact-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecg%2Freact-hooks/lists"}