{"id":15022263,"url":"https://github.com/jlalmes/simple-atom","last_synced_at":"2025-08-06T16:33:37.641Z","repository":{"id":49685433,"uuid":"435712062","full_name":"jlalmes/simple-atom","owner":"jlalmes","description":"Simple atomic state that can be updated outside of React components.","archived":false,"fork":false,"pushed_at":"2022-08-30T14:44:12.000Z","size":1495,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-22T12:56:25.816Z","etag":null,"topics":["atomic","jotai","reactjs","state","zustand"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/simple-atom","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/jlalmes.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"jlalmes"}},"created_at":"2021-12-07T02:06:08.000Z","updated_at":"2024-05-10T03:18:58.000Z","dependencies_parsed_at":"2022-09-05T13:22:32.676Z","dependency_job_id":null,"html_url":"https://github.com/jlalmes/simple-atom","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/jlalmes/simple-atom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlalmes%2Fsimple-atom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlalmes%2Fsimple-atom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlalmes%2Fsimple-atom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlalmes%2Fsimple-atom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlalmes","download_url":"https://codeload.github.com/jlalmes/simple-atom/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlalmes%2Fsimple-atom/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269112699,"owners_count":24362021,"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-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["atomic","jotai","reactjs","state","zustand"],"created_at":"2024-09-24T19:57:42.998Z","updated_at":"2025-08-06T16:33:37.306Z","avatar_url":"https://github.com/jlalmes.png","language":"TypeScript","funding_links":["https://github.com/sponsors/jlalmes"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003esimple-atom\u003c/h1\u003e\n  \u003cp\u003eIf Jotai \u0026 Zustand had a baby 👼\u003c/p\u003e\n  \u003ca href=\"https://www.npmjs.com/package/simple-atom\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/simple-atom.svg?style=flat\u0026color=brightgreen\" target=\"_blank\" /\u003e\u003c/a\u003e\n  \u003ca href=\"./LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-black\" /\u003e\u003c/a\u003e\n  \u003cbr /\u003e\n  \u003chr /\u003e\n\u003c/div\u003e\n\nSimple atomic state that can be updated outside of the React life-cycle.\n\n## Why use `simple-atom`?\n\n- Update state **outside of a React component.**\n\n- No need for React Context, store your atoms in **global scope**.\n\n- **Familiar API**, identical usage to `React.setState`.\n\n- First class **Typescript support**.\n\n- It's simple, open source and it's tiny! **\u003c250 bytes** gzipped.\n\n## Installation\n\n```bash\n  npm install simple-atom\n```\n\nPlease ensure you have installed [`react`](https://github.com/facebook/react) at version `v16.8.0` or higher.\n\n## Examples\n\n#### Basic usage\n\n```javascript\nimport React from 'react';\n// Import 'simple-atom'\nimport { createAtom, useAtom } from 'simple-atom';\n\n// Create an atom with 'createAtom'\nconst userAtom = createAtom({ name: 'James', age: 25 });\n\nconst MyComponent = () =\u003e {\n  // Get current value and setter function with 'useAtom' hook\n  const [user, setUser] = useAtom(userAtom);\n\n  if (!user) {\n    return \u003ch1\u003eYou are logged out\u003c/h1\u003e;\n  }\n\n  return \u003cbutton onClick={() =\u003e setUser(null)}\u003eLogout\u003c/button\u003e;\n};\n```\n\n#### Update component state outside of React\n\n```javascript\n// == MyComponent.jsx ==\nimport React from 'react';\nimport { createAtom, useAtom } from 'simple-atom';\n\nexport const isLoadingAtom = createAtom(false);\n\nconst MyComponent = () =\u003e {\n    const [isLoading] = useAtom(isLoadingAtom);\n\n    if (isLoading) {\n        return (\n            \u003cdiv\u003eLoading, please wait...\u003c/div\u003e\n        );\n    }\n\n    return (\n        // ...\n    );\n}\n\n// == other-application-file.js ==\nimport { isLoadingAtom } from './MyComponent.jsx';\n\n// MyComponent will now re-render with the updated isLoading state\nisLoadingAtom.value = true;\n\n```\n\n#### Subscribe to state changes\n\n```javascript\nimport React from 'react';\nimport { createAtom, useAtom } from 'simple-atom';\n\nconst darkModeAtom = createAtom(() =\u003e {\n  if (typeof window === 'undefined') {\n    return false;\n  }\n  return window.localStorage.getItem('dark-mode') === 'true';\n});\n\n// Add a subscriber that is triggered on atom value change\ndarkModeAtom.subscribe((value) =\u003e {\n  window.localStorage.setItem('dark-mode', value.toString());\n});\n\nconst MyComponent = () =\u003e {\n  const [darkMode, setDarkMode] = useAtom(darkModeAtom);\n\n  return \u003cbutton onClick={() =\u003e setDarkMode(!darkMode)}\u003eToggle dark mode\u003c/button\u003e;\n};\n```\n\n#### With Typescript\n\n```typescript\nimport { createAtom } from 'simple-atom';\n\ntype User = { name: string; age: number } | null;\n\nconst userAtom = createAtom\u003cUser\u003e({ name: 'James', age: 25 });\n```\n\n## Acknowledgements\n\nThis package was inspired by these projects.\n\n- [React](https://reactjs.org/docs/hooks-reference.html#usestate)\n- [Jotai](https://github.com/pmndrs/jotai)\n- [Zustand](https://github.com/pmndrs/zustand)\n\n## Authors\n\n- [James Berry (@jlalmes)](https://twitter.com/@jlalmes)\n\nContributions \u0026 PRs are always welcome! 🙌\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlalmes%2Fsimple-atom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlalmes%2Fsimple-atom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlalmes%2Fsimple-atom/lists"}