{"id":21508091,"url":"https://github.com/wtnm/react-global-store-hook","last_synced_at":"2025-03-17T14:46:09.266Z","repository":{"id":128372885,"uuid":"394227191","full_name":"wtnm/react-global-store-hook","owner":"wtnm","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-14T20:12:31.000Z","size":156,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-14T21:32:35.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/wtnm.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}},"created_at":"2021-08-09T09:20:01.000Z","updated_at":"2024-03-14T21:32:38.249Z","dependencies_parsed_at":"2023-11-09T13:02:29.575Z","dependency_job_id":"3980a86c-e0e5-496d-a776-521f03a04e2e","html_url":"https://github.com/wtnm/react-global-store-hook","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"79a14c9cabcfd03e764db13fac602fd0e4a52fa3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnm%2Freact-global-store-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnm%2Freact-global-store-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnm%2Freact-global-store-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtnm%2Freact-global-store-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wtnm","download_url":"https://codeload.github.com/wtnm/react-global-store-hook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244054434,"owners_count":20390550,"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":[],"created_at":"2024-11-23T20:45:44.057Z","updated_at":"2025-03-17T14:46:09.230Z","avatar_url":"https://github.com/wtnm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n\u003c!-- toc --\u003e\n\n\n\n\u003c!-- tocstop --\u003e\n\n## Overview\n`react-global-store-hook` - global store based on react hooks\n\n## Installation\n\nTo install the stable version:\n\n```\nnpm install --save react-global-store-hook\n```\n\n\n## Quick example\n```jsx\nimport GlobalStore from 'react-global-store-hook';\n\nconst store = new GlobalStore({ count: 0 });\n\nsetInterval(() =\u003e {\n  store.set('count', store.get('count') + 1);\n}, 1000);\n\nexport function SecondsCounter() {\n  const count = store.useSubscribe('count');\n  return \u003cdiv\u003e{count}\u003c/div\u003e;\n}\n\nconst unsubscribe = store.subsctibe('count', (value) =\u003e console.log(value));\n```\n\n## Documentation\n### GlobalStore(initialState: { [key: string]: any } = {})\n```jsx\nimport GlobalStore from 'react-global-store-hook';\nconst store = new GlobalStore();\n```\nStore constructor. Can be initialized with initial state.\n\n### GlobalStore methods\n\n#### useSubscribe = (...paths: Array\u003cstring | string[]\u003e): any | any[] | { prev: any, current: any }\nReact hook to subscribe for store updates in react functional components.\n\nIf no arguments passed, then subscribes to all changes and returns value in format `{ prev: any, current: any }`.\n\nIf one argument passed returns single value in `path = paths[0]`.\n\nOtherwise return tuple of values in each `path of paths`\n\nExample:\n```jsx\nconst store = new GlobalStore({ one: 1, two: { deep: 2 }, three: 3 });\n\nexport function Example() {\n  const deepTwo = store.useSubscribe(['two', 'deep']);\n  const [one, three] = store.useSubscribe('one', 'three');\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003e{deepTwo}\u003c/div\u003e {/* 2 */}\n      \u003cdiv\u003e{one}\u003c/div\u003e {/* 1 */}\n      \u003cdiv\u003e{three}\u003c/div\u003e {/* 3 */}\n    \u003c/div\u003e\n  );\n}\n```\n#### subscribe = (path: string | string[], subscriber: (value: any) =\u003e void): Function\nSubscribes `subscriber` for store value updates in `path`. Returns function to unsubscribe\n\n#### set = (path: string | string[], value: any): void\nSet new `value` in store `path`\n\n#### get = (path: string | string[]): any\nGet `value` in store `path`\n\n#### keys(): string[]\nReturns all store keys","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtnm%2Freact-global-store-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwtnm%2Freact-global-store-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtnm%2Freact-global-store-hook/lists"}