{"id":25933958,"url":"https://lostpebble.github.io/pullstate/","last_synced_at":"2025-03-04T00:56:32.673Z","repository":{"id":38454807,"uuid":"171061051","full_name":"lostpebble/pullstate","owner":"lostpebble","description":"Simple state stores using immer and React hooks - re-use parts of your state by pulling it anywhere you like!","archived":false,"fork":false,"pushed_at":"2023-06-07T17:51:30.000Z","size":4559,"stargazers_count":1073,"open_issues_count":46,"forks_count":23,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-02-28T22:21:06.214Z","etag":null,"topics":["hooks","immer","react","reactjs","server-side-rendering","state","state-management"],"latest_commit_sha":null,"homepage":"https://lostpebble.github.io/pullstate","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/lostpebble.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},"funding":{"github":["lostpebble"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-02-16T23:02:06.000Z","updated_at":"2025-02-23T12:48:40.000Z","dependencies_parsed_at":"2024-01-13T21:11:13.707Z","dependency_job_id":null,"html_url":"https://github.com/lostpebble/pullstate","commit_stats":{"total_commits":304,"total_committers":10,"mean_commits":30.4,"dds":"0.10855263157894735","last_synced_commit":"2a4651a8e16f543b484298592cf894c281c98c16"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lostpebble%2Fpullstate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lostpebble%2Fpullstate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lostpebble%2Fpullstate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lostpebble%2Fpullstate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lostpebble","download_url":"https://codeload.github.com/lostpebble/pullstate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241763681,"owners_count":20016162,"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":["hooks","immer","react","reactjs","server-side-rendering","state","state-management"],"created_at":"2025-03-04T00:56:31.954Z","updated_at":"2025-03-04T00:56:32.664Z","avatar_url":"https://github.com/lostpebble.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/lostpebble/pullstate/raw/master/graphics/logo-newest.png\" alt=\"Pullstate\" /\u003e\n\u003c/p\u003e\n\n### pullstate\n\n\u003e Ridiculously simple state stores with performant retrieval anywhere\n\u003e in your React tree using the wonderful concept of React hooks!\n\n* ~7KB minified and gzipped! (excluding Immer and React)\n* Built with Typescript, providing a great dev experience if you're using it too\n* Uses [immer](https://github.com/mweststrate/immer) for state updates - easily and safely mutate your state directly!\n* **NEW** - [Create async actions](https://lostpebble.github.io/pullstate/docs/async-actions-introduction) and use React hooks or `\u003cSuspense/\u003e` to have complete control over their UI states!\n\n_Originally inspired by the now seemingly abandoned library - [bey](https://github.com/jamiebuilds/bey). Although substantially\ndifferent now- with Server-side rendering and Async Actions built in! Bey was in turn inspired by\n[react-copy-write](https://github.com/aweary/react-copy-write)._\n\nTry out a quick example:\n\n[![Edit Pullstate Client-only Example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/myvj8zzypp)\n\n### 🎉 **[New documentation site is live!](https://lostpebble.github.io/pullstate/)**\n\n* [Installation](https://lostpebble.github.io/pullstate/docs/installation)\n* [Quick example](https://lostpebble.github.io/pullstate/docs/quick-example)\n* [Quick example - Server rendering](https://lostpebble.github.io/pullstate/docs/quick-example-server-rendered)\n* [Async Actions](https://lostpebble.github.io/pullstate/docs/async-actions-introduction)\n  * [Creation](https://lostpebble.github.io/pullstate/docs/async-actions-creating)\n  * [Usage](https://lostpebble.github.io/pullstate/docs/async-action-use)\n  * [Async action hooks](https://lostpebble.github.io/pullstate/docs/async-hooks-overview)\n\n---\n\n# **Let's dive right in**\n\n\u003e This is taken directly from [the documentation site](https://lostpebble.github.io/pullstate/docs/quick-example), to give you a quick overview of Pullstate here on github. Be sure to check out the site to learn more.\n\nTo start off, install `pullstate`.\n\n```bash\nyarn add pullstate\n```\n\n## Create a store\n\nDefine the first **state store**, by passing an initial state to `new Store()`:\n\n\u003c!--JavaScript--\u003e\n```jsx\nimport { Store } from \"pullstate\";\n\nexport const UIStore = new Store({\n  isDarkMode: true,\n});\n```\n\n## Read our store's state\n\nThen, in React, we can start using the state of that store using a simple hook `useState()`:\n\n```tsx\nimport * as React from \"react\";\nimport { UIStore } from \"./UIStore\";\n\nexport const App = () =\u003e {\n  const isDarkMode = UIStore.useState(s =\u003e s.isDarkMode);\n\n  return (\n    \u003cdiv\n      style={{\n        background: isDarkMode ? \"black\" : \"white\",\n        color: isDarkMode ? \"white\" : \"black\",\n      }}\u003e\n      \u003ch1\u003eHello Pullstate\u003c/h1\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\nThe argument to `useState()` over here (`s =\u003e s.isDarkMode`), is a selection function that ensures we select only the state that we actually need for this component. This is a big performance booster, as we only listen for changes (and if changed, re-render the component) on the exact returned values - in this case, simply the value of `isDarkMode`.\n\n---\n\n## Add interaction (update state)\n\nGreat, so we are able to pull our state from `UIStore` into our App. Now lets add some basic interaction with a `\u003cbutton\u003e`:\n\n```tsx\n  return (\n    \u003cdiv\n      style={{\n        background: isDarkMode ? \"black\" : \"white\",\n        color: isDarkMode ? \"white\" : \"black\",\n      }}\u003e\n      \u003ch1\u003eHello Pullstate\u003c/h1\u003e\n      \u003cbutton\n        onClick={() =\u003e\n          UIStore.update(s =\u003e {\n            s.isDarkMode = !isDarkMode;\n          })\n        }\u003e\n        Toggle Dark Mode\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n```\n\nNotice how we call `update()` on `UIStore`, inside which we directly mutate the store's state. This is all thanks to the power of `immer`, which you can check out [here](https://github.com/immerjs/immer).\n\nAnother pattern, which helps to illustrate this further, would be to actually define the action of toggling dark mode to a function on its own:\n\n\u003c!--JavaScript--\u003e\n```tsx\nfunction toggleMode(s) {\n  s.isDarkMode = !s.isDarkMode;\n}\n\n// ...in our \u003cbutton\u003e code\n\u003cbutton onClick={() =\u003e UIStore.update(toggleMode)}\u003eToggle Dark Mode\u003c/button\u003e\n```\n\nBasically, to update our app's state all we need to do is create a function (inline arrow function or regular) which takes the current store's state and mutates it to whatever we'd like the next state to be.\n\n## Omnipresent state updating\n\nSomething interesting to notice at this point is that we are just importing `UIStore` directly and running `update()` on it:\n\n```tsx\nimport { UIStore } from \"./UIStore\";\n\n// ...in our \u003cbutton\u003e code\n\u003cbutton onClick={() =\u003e UIStore.update(toggleMode)}\u003eToggle Dark Mode\u003c/button\u003e\n```\n\nAnd our components are being updated accordingly. We have freed our app's state from the confines of the component! This is one of the main advantages of Pullstate - allowing us to separate our state concerns from being locked in at the component level and manage things easily at a more global level from which our components listen and react (through our `useStoreState()` hooks).\n","funding_links":["https://github.com/sponsors/lostpebble"],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/lostpebble.github.io%2Fpullstate%2F","html_url":"https://awesome.ecosyste.ms/projects/lostpebble.github.io%2Fpullstate%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/lostpebble.github.io%2Fpullstate%2F/lists"}