{"id":13454506,"url":"https://github.com/LegendApp/legend-state","last_synced_at":"2025-03-24T05:33:57.424Z","repository":{"id":50634227,"uuid":"516262843","full_name":"LegendApp/legend-state","owner":"LegendApp","description":"Legend-State is a super fast and powerful state library that enables fine-grained reactivity and easy automatic persistence","archived":false,"fork":false,"pushed_at":"2024-07-31T00:53:30.000Z","size":8580,"stargazers_count":2608,"open_issues_count":59,"forks_count":77,"subscribers_count":22,"default_branch":"main","last_synced_at":"2024-08-05T09:19:00.526Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://legendapp.com/open-source/state/","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/LegendApp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["jmeistrich"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2022-07-21T07:06:08.000Z","updated_at":"2024-08-25T01:43:03.412Z","dependencies_parsed_at":"2023-10-02T14:43:20.208Z","dependency_job_id":"583ae653-1463-4544-b164-81c89ba85477","html_url":"https://github.com/LegendApp/legend-state","commit_stats":{"total_commits":1220,"total_committers":11,"mean_commits":110.9090909090909,"dds":0.03934426229508192,"last_synced_commit":"d0b9a97a6ccd312ddaa7939c5d84d22c00b465dc"},"previous_names":[],"tags_count":474,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegendApp%2Flegend-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegendApp%2Flegend-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegendApp%2Flegend-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegendApp%2Flegend-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LegendApp","download_url":"https://codeload.github.com/LegendApp/legend-state/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245217433,"owners_count":20579291,"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-07-31T08:00:54.785Z","updated_at":"2025-03-24T05:33:56.755Z","avatar_url":"https://github.com/LegendApp.png","language":"TypeScript","funding_links":["https://github.com/sponsors/jmeistrich"],"categories":["TypeScript","State Management","⚙️ Development Tools \u0026 Libraries"],"sub_categories":["Graphics \u0026 Drawing","State Management \u0026 Sync"],"readme":"# Legend-State\n\nLegend-State is a super fast all-in-one state and sync library that lets you write less code to make faster apps. Legend-State has four primary goals:\n\n### 1. 🦄 As easy as possible to use\n\nThere is no boilerplate and there are no contexts, actions, reducers, dispatchers, sagas, thunks, or epics. It doesn't modify your data at all, and you can just call `get()` to get the raw data and `set()` to change it.\n\nIn React components you can call `use()` on any observable to get the raw data and automatically re-render whenever it changes.\n\n```jsx\nimport { observable, observe } from \"@legendapp/state\"\nimport { observer } from \"@legendapp/state/react\"\n\nconst settings$ = observable({ theme: 'dark' })\n\n// get returns the raw data\nsettings$.theme.get() // 'dark'\n// set sets\nsettings$.theme.set('light')\n\n// Computed observables with just a function\nconst isDark$ = observable(() =\u003e settings$.theme.get() === 'dark')\n\n// observing contexts re-run when tracked observables change\nobserve(() =\u003e {\n  console.log(settings$.theme.get())\n})\n\nconst Component = observer(function Component() {\n    const theme = state$.settings.theme.get()\n\n    return \u003cdiv\u003eTheme: {theme}\u003c/div\u003e\n})\n```\n\n### 2. ⚡️ The fastest React state library\n\nLegend-State beats every other state library on just about every metric and is so optimized for arrays that it even beats vanilla JS on the \"swap\" and \"replace all rows\" benchmarks. At only `4kb` and with the massive reduction in boilerplate code, you'll have big savings in file size too.\n\n\u003cp\u003e\n    \u003cimg src=\"https://www.legendapp.com/img/dev/state/times.png\" /\u003e\n\u003c/p\u003e\n\nSee [Fast 🔥](https://www.legendapp.com/open-source/state/v3/intro/fast/) for more details of why Legend-State is so fast.\n\n### 3. 🔥 Fine-grained reactivity for minimal renders\n\nLegend-State lets you make your renders super fine-grained, so your apps will be much faster because React has to do less work. The best way to be fast is to render less, less often.\n\n```jsx\nfunction FineGrained() {\n    const count$ = useObservable(0)\n\n    useInterval(() =\u003e {\n        count$.set(v =\u003e v + 1)\n    }, 600)\n\n    // The text updates itself so the component doesn't re-render\n    return (\n        \u003cdiv\u003e\n            Count: \u003cMemo\u003e{count$}\u003c/Memo\u003e\n        \u003c/div\u003e\n    )\n}\n```\n\n### 4. 💾 Powerful sync and persistence\n\nLegend-State includes a powerful [sync and persistence system](../../usage/persist-sync). It easily enables local-first apps by optimistically applying all changes locally first, retrying changes even after restart until they eventually sync, and syncing minimal diffs. We use Legend-State as the sync systems in [Legend](https://legendapp.com) and [Bravely](https://bravely.io), so it is by necessity very full featured while being simple to set up.\n\nLocal persistence plugins for the browser and React Native are included, with sync plugins for [Keel](https://www.keel.so), [Supabase](https://www.supabase.com), [TanStack Query](https://tanstack.com/query), and `fetch`.\n\n```js\nconst state$ = observable(\n    users: syncedKeel({\n        list: queries.getUsers,\n        create: mutations.createUsers,\n        update: mutations.updateUsers,\n        delete: mutations.deleteUsers,\n        persist: { name: 'users', retrySync: true },\n        debounceSet: 500,\n        retry: {\n            infinite: true,\n        },\n        changesSince: 'last-sync',\n    }),\n    // direct link to my user within the users observable\n    me: () =\u003e state$.users['myuid']\n)\n\nobserve(() =\u003e {\n    // get() activates through to state$.users and starts syncing.\n    // it updates itself and re-runs observers when name changes\n    const name = me$.name.get()\n})\n\n// Setting a value goes through to state$.users and saves update to server\nme$.name.set('Annyong')\n```\n\n## Install\n\n`bun add @legendapp/state` or `npm install @legendapp/state` or `yarn add @legendapp/state`\n\n## Highlights\n\n- ✨ Super easy to use 😌\n- ✨ Super fast ⚡️\n- ✨ Super small at 4kb 🐥\n- ✨ Fine-grained reactivity 🔥\n- ✨ No boilerplate\n- ✨ Designed for maximum performance and scalability\n- ✨ React components re-render only on changes\n- ✨ Very strongly typed with TypeScript\n- ✨ Persistence plugins for automatically saving/loading from storage\n- ✨ State can be global or within components\n\n[Read more](https://www.legendapp.com/open-source/state/v3/intro/why/) about why Legend-State might be right for you.\n\n## Documentation\n\nSee [the documentation site](https://www.legendapp.com/open-source/state/).\n\n## Community\n\nJoin us on [Discord](https://discord.gg/5CBaNtADNX) to get involved with the Legend community.\n\n## 👩‍⚖️ License\n\n[MIT](LICENSE)\n\n---\n\nLegend-State is created and maintained by [Jay Meistrich](https://github.com/jmeistrich) with [Legend](https://www.legendapp.com) and [Bravely](https://www.bravely.io).\n\n\u003cp\u003e\n    \u003ca href=\"https://www.legendapp.com\"\u003e\u003cimg src=\"https://www.legendapp.com/img/LogoTextOnWhite.png\" height=\"56\" alt=\"Legend\" /\u003e\u003c/a\u003e\n    \u003cspan\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003c/span\u003e\n    \u003ca href=\"https://www.bravely.io\"\u003e\u003cimg src=\"https://www.legendapp.com/img/bravely-logo.png\" height=\"56\" alt=\"Bravely\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLegendApp%2Flegend-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLegendApp%2Flegend-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLegendApp%2Flegend-state/lists"}