{"id":26454092,"url":"https://github.com/puema/react-station","last_synced_at":"2025-03-18T19:39:15.113Z","repository":{"id":39250060,"uuid":"236371634","full_name":"puema/react-station","owner":"puema","description":"🚉 Easy to use state and actions for React. Optimized rerenders with state selection. Typesafe. Async actions. https://puema.github.io/react-station/","archived":false,"fork":false,"pushed_at":"2023-01-05T05:47:01.000Z","size":2086,"stargazers_count":4,"open_issues_count":19,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T15:39:11.549Z","etag":null,"topics":["actions","react-station","redux","state-management","typesafe"],"latest_commit_sha":null,"homepage":"","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/puema.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":"2020-01-26T20:27:14.000Z","updated_at":"2020-11-10T08:24:36.000Z","dependencies_parsed_at":"2023-02-03T14:01:35.843Z","dependency_job_id":null,"html_url":"https://github.com/puema/react-station","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/puema%2Freact-station","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puema%2Freact-station/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puema%2Freact-station/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puema%2Freact-station/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puema","download_url":"https://codeload.github.com/puema/react-station/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244228049,"owners_count":20419342,"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":["actions","react-station","redux","state-management","typesafe"],"created_at":"2025-03-18T19:39:14.526Z","updated_at":"2025-03-18T19:39:15.103Z","avatar_url":"https://github.com/puema.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"128px\" src=\"./docs/station.png\" alt=\"station\"\u003e\n  \u003cp\u003e\n    React Station - \u003cb\u003eSta\u003c/b\u003ete \u0026 Ac\u003cb\u003etion\u003c/b\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    Easy to Use • Hooks • State Selection • Optimized Rerenders • Typesafe • Async Support\u003cbr/\u003e\n    \u003ca href=\"https://puema.github.io/react-station/\"\u003eDemo\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://www.npmjs.org/package/react-station\"\u003e\n      \u003cimg src=\"https://img.shields.io/npm/v/react-station.svg?style=flat-square\" alt=\"npm version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.org/package/react-station\"\u003e\n      \u003cimg src=\"https://img.shields.io/npm/dw/react-station.svg?style=flat-square\" alt=\"npm downloads\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://bundlephobia.com/result?p=react-station\"\u003e\n      \u003cimg src=\"https://img.shields.io/bundlephobia/minzip/react-station?style=flat-square\" alt=\"gzip size\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://prettier.io/\"\u003e\n      \u003cimg alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n## Why\n\n😎 Easy to use \u003cbr /\u003e\n🦶 Small footprint \u003cbr /\u003e\n🚀 Performance optimized \u003cbr /\u003e\n⛑ Typesafe with TypeScript \u003cbr /\u003e\n\n[Redux](https://github.com/reduxjs/react-redux) was always too verbose for my personal taste. React [Contex](https://reactjs.org/docs/context.html) is great, but there is no optimized state subscribtion. I do like the approach of [unistore](https://reactjs.org/docs/context.html) with the bound actions a lot. However I prefer Hooks over the `connect()` API and I wanted the actions to be part of the store. So I created react-station, a simple state management with a lot of parallels to unistore and `useSelect()` from redux.\n\n## Usage\n\n```jsx\nconst initialState = {\n  count: 0,\n};\n\ntype State = typeof initialState;\n\nconst actions = {\n  // The Current state is passed as first parameter to the actions\n  increment({ count }: State) {\n    // The return value should be a Partial\u003cState\u003e and will be merged\n    return { count: count + 1 };\n  },\n\n  // Payload is available as following parameters\n  add({ count }: State, value: number) {\n    return {\n      count: count + value,\n    };\n  },\n\n  // Actions can also be async\n  async calculateSum({ count }: State, value: number) {\n    const result = await asyncCalculation(count, value);\n    // Make sure to access state after async calls via\n    // store.getState() to avoid race conditions\n    return {\n      count: result,\n    };\n  },\n};\n\n// Multiple instances of different stores can be created\nconst store = createStore(initialState, actions);\n\nexport const Component = () =\u003e {\n  // Simply retrieve state and actions via hooks\n  const { state, actions } = useStore(store);\n  // Or select a part of the state to avoid unnecessary rerenders\n  const { state: state2 } = useStore(store, s =\u003e s.count);\n\n  const { add } = actions;\n\n  add(1); // ok\n  add('1'); // Error: '1' is not assignable to parameter of type 'number'.\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuema%2Freact-station","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuema%2Freact-station","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuema%2Freact-station/lists"}