{"id":22665114,"url":"https://github.com/ekwoka/preact-global-state","last_synced_at":"2026-04-17T13:32:51.494Z","repository":{"id":43929260,"uuid":"498610180","full_name":"ekwoka/preact-global-state","owner":"ekwoka","description":"Global State Manager for Preact with Types","archived":false,"fork":false,"pushed_at":"2024-10-01T17:22:15.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-25T10:44:09.737Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ekwoka.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"ekwoka"}},"created_at":"2022-06-01T06:01:49.000Z","updated_at":"2023-06-17T16:37:14.000Z","dependencies_parsed_at":"2024-12-09T13:20:35.064Z","dependency_job_id":"268a2003-eee0-42cb-a8e9-d18b7b53ffa4","html_url":"https://github.com/ekwoka/preact-global-state","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"5f3b1dab49ccae26084028d9fc921db2de71b708"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ekwoka/preact-global-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekwoka%2Fpreact-global-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekwoka%2Fpreact-global-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekwoka%2Fpreact-global-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekwoka%2Fpreact-global-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekwoka","download_url":"https://codeload.github.com/ekwoka/preact-global-state/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekwoka%2Fpreact-global-state/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31931423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-12-09T13:19:35.153Z","updated_at":"2026-04-17T13:32:51.475Z","avatar_url":"https://github.com/ekwoka.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ekwoka"],"categories":[],"sub_categories":[],"readme":"# Preact Global State\n\n[\u003cimg src=\"https://img.shields.io/npm/v/@ekwoka/preact-global-state?style=for-the-badge\"\u003e](https://www.npmjs.com/package/@ekwoka/preact-global-state)\n\u003cimg src=\"https://img.shields.io/npm/types/@ekwoka/preact-global-state?label=%20\u0026amp;logo=typescript\u0026amp;logoColor=white\u0026amp;style=for-the-badge\"\u003e\n\u003cimg src=\"https://img.shields.io/npm/dt/@ekwoka/preact-global-state?style=for-the-badge\" \u003e\n[\u003cimg src=\"https://img.shields.io/bundlephobia/minzip/@ekwoka/preact-global-state?style=for-the-badge\"\u003e](https://bundlephobia.com/package/@ekwoka/preact-global-state)\n\nPreact Global State is a simple state management library for Preact, enabling the sharing of state between components, similar to React's Context API, or other libraries like Redux. The big benefit of Preact Global State over these alternatives is the ease-of use and surgical precision (improved even further with the use of signals instead of classic state).\n\nThis project began as a rewrite of `preact-global-state` but has since been dramatically altered and extended. With `2.0.0`, the core utilizes `@preact/signals` (and requires it as a peer). This does increase the overall footprint of adding this to a non-signal project, but reduces the footprint when already using signals.\n\nIf you are not using `signals` and just want a global equivalent to `useState`, you can install `1.0.1` instead.\n\n## Installation\n\n```bash\npnpm add @ekwoka/preact-global-state # for signals\npnpm add @ekwoka/preact-global-state@1.0.1  # for non-signals projects\n```\n\n## Usage\n\n### Classic state\n\n```ts\nconst [counter, setCounter] = useGlobalState\u003cnumber\u003e('my-counter', 0); // (state label: string; initial value?: any)\n\nreturn (\n  \u003cdiv\u003e\n    \u003cbutton onClick={() =\u003e setCounter(1)}\u003e /* directly setting the state Set to 1! */\u003c/button\u003e\n    \u003cbutton onClick={() =\u003e setCounter((prev) =\u003e prev + 1)}\u003e /* using a state function to update the state Increment! */\u003c/button\u003e\n  \u003c/div\u003e\n);\n```\n\nAnd in another\n\n```ts\nconst [counter] = useGlobalState\u003cnumber\u003e('my-counter', 0);\n\nreturn (\n  \u003cdiv\u003e\n    \u003cp\u003e{counter}\u003c/p\u003e\n  \u003c/div\u003e\n);\n```\n\n### Using signals\n\n```ts\nconst count = useGlobalSignal\u003cnumber\u003e('my-counter', 0); // (state label: string; initial value?: any)\n\nreturn (\n  \u003cdiv\u003e\n    \u003cbutton onClick={() =\u003e count.value++}\u003e /* Incrementing the signal value */ \u003c/button\u003e\n  \u003c/div\u003e\n);\n```\n\nAnd in another\n\n```ts\nconst count = useGlobalSignal\u003cnumber\u003e('my-counter', 0);\n\nreturn (\n  \u003cdiv\u003e\n    \u003cp\u003e{count}\u003c/p\u003e\n  \u003c/div\u003e\n);\n```\n\nThis state can be shared among any number of components, and the use of `useGlobalState` and `useGlobalSignal` can be mixed! This allows you to get the benefits of a global signal while also having state updaters to pass to external libraries, or to mix legacy components with newer signals based components.\n\n### Store\n\nOne consideration of these hooks is that the first calling of a hook with a specific default value will set that value to the state. Subsequent initializations will ignore the default value.\n\nWhile smart usage can ensure that this is not an issue, it could be the cause of any issues.\n\nTo avoid this, or to simply enable an explicit initialization of the global state, you can use the `Store` function outside of components (or at some root level).\n\n```ts\nStore({\n  hello: 'world',\n  foo: 'bar',\n  blazeit: 420\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekwoka%2Fpreact-global-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekwoka%2Fpreact-global-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekwoka%2Fpreact-global-state/lists"}