{"id":26713714,"url":"https://github.com/spiderpoul/use-global-state-react","last_synced_at":"2025-04-13T22:11:19.359Z","repository":{"id":57388086,"uuid":"441413631","full_name":"spiderpoul/use-global-state-react","owner":"spiderpoul","description":"Simple useGlobalState hook for React!","archived":false,"fork":false,"pushed_at":"2021-12-27T18:57:02.000Z","size":68,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T12:37:21.653Z","etag":null,"topics":["react","react-hooks","react-state","react-state-management","usestate"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spiderpoul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-24T08:41:54.000Z","updated_at":"2025-02-11T15:51:31.000Z","dependencies_parsed_at":"2022-08-31T04:12:13.404Z","dependency_job_id":null,"html_url":"https://github.com/spiderpoul/use-global-state-react","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/spiderpoul%2Fuse-global-state-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiderpoul%2Fuse-global-state-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiderpoul%2Fuse-global-state-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spiderpoul%2Fuse-global-state-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spiderpoul","download_url":"https://codeload.github.com/spiderpoul/use-global-state-react/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788925,"owners_count":21161727,"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","react-hooks","react-state","react-state-management","usestate"],"created_at":"2025-03-27T12:29:58.225Z","updated_at":"2025-04-13T22:11:19.329Z","avatar_url":"https://github.com/spiderpoul.png","language":"JavaScript","readme":"## useGlobalState\n\n**Simple useGlobalState hook for React!** \n\nDo you need your data shared across other components, and you simply don't want to pass props all the way down, create context or use state management tool?\n\nJust use `useGlobalState`, it's really simple and does all the magic for you:\n- first argument is a key for your store\n- second argument is optional - initial value\n\nTry [Codesandbox example](https://codesandbox.io/s/boring-cerf-j4ub4)\n\n### Example:\n```ts\nimport { useGlobalState } from 'use-global-state-react';\n\nconst TASK_STORE_KEY = 'tasks';\n\nconst Tasks = () =\u003e {\n    const [tasks, setTasks] = useGlobalState\u003cstring[]\u003e(TASK_STORE_KEY, []);\n    \n    ...\n}\n```\n\nand then you can use the same hook everywhere, data will be shared across components and component will rerender if changes happened in store:\n\n```ts\nconst AddTaskButton = () =\u003e {\n    const [, setTasks] = useGlobalState(TASK_STORE_KEY, []);\n    \n    const onTaskAdd = (newTask: stirng) =\u003e setTasks(prev =\u003e [...prev, newTask]);\n    \n    ...\n}\n\nconst TasksTotal = () =\u003e {\n    const [tasks] = useGlobalState\u003cstring[]\u003e(TASK_STORE_KEY, []);\n    \n    return tasks.length;\n}\n```\n\n\nor use helper `createGlobalStore` to create custom hook with shared data:\n\n```ts\nimport { createGlobalStore } from 'use-global-state-react';\n\nconst useTasks = createGlobalStore\u003cstring[]\u003e(TASK_STORE_KEY, []);\n\n\nconst Tasks = () =\u003e {\n    const [tasks, setTasks] = useTasks();\n    ...\n}\n\n```\n\n## Installation\n\n```\n  npm i use-global-state-react\n```\n\nor\n\n```\n  yarn add use-global-state-react\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspiderpoul%2Fuse-global-state-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspiderpoul%2Fuse-global-state-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspiderpoul%2Fuse-global-state-react/lists"}