{"id":15118497,"url":"https://github.com/nanxiaobei/flooks","last_synced_at":"2025-04-04T15:06:05.836Z","repository":{"id":38863207,"uuid":"199540666","full_name":"nanxiaobei/flooks","owner":"nanxiaobei","description":"🍸 Auto Optimized State Manager for React Hooks","archived":false,"fork":false,"pushed_at":"2024-08-08T17:31:58.000Z","size":1195,"stargazers_count":352,"open_issues_count":0,"forks_count":41,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-28T05:02:21.683Z","etag":null,"topics":["flooks","flux","hooks","model","react","redux","state","store"],"latest_commit_sha":null,"homepage":"","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/nanxiaobei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2019-07-29T23:37:39.000Z","updated_at":"2025-03-24T01:22:02.000Z","dependencies_parsed_at":"2023-02-09T10:31:05.059Z","dependency_job_id":"ce00b059-83a4-4dfa-8dd7-36575c355353","html_url":"https://github.com/nanxiaobei/flooks","commit_stats":{"total_commits":297,"total_committers":3,"mean_commits":99.0,"dds":0.07070707070707072,"last_synced_commit":"e9f24b3aebf8df5544237437c176e5da009d7760"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanxiaobei%2Fflooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanxiaobei%2Fflooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanxiaobei%2Fflooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanxiaobei%2Fflooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanxiaobei","download_url":"https://codeload.github.com/nanxiaobei/flooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247123107,"owners_count":20887261,"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":["flooks","flux","hooks","model","react","redux","state","store"],"created_at":"2024-09-26T01:46:17.934Z","updated_at":"2025-04-04T15:06:05.801Z","avatar_url":"https://github.com/nanxiaobei.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\nLink in bio to **widgets**,\nyour online **home screen**. ➫ [🔗 kee.so](https://kee.so/)\n\n\u003c/div\u003e\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003eflooks\u003c/h1\u003e\n\nState Manager for React Hooks, Auto Optimized\n\n[![npm](https://img.shields.io/npm/v/flooks?style=flat-square)](https://www.npmjs.com/package/flooks)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/nanxiaobei/flooks/test.yml?branch=main\u0026style=flat-square)](https://github.com/nanxiaobei/flooks/actions/workflows/test.yml)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/flooks?style=flat-square)](https://bundlephobia.com/result?p=flooks)\n[![npm type definitions](https://img.shields.io/npm/types/typescript?style=flat-square)](https://github.com/nanxiaobei/flooks/blob/main/src/index.ts)\n[![GitHub](https://img.shields.io/github/license/nanxiaobei/flooks?style=flat-square)](https://github.com/nanxiaobei/flooks/blob/main/LICENSE)\n\nEnglish · [简体中文](./README.zh-CN.md)\n\n\u003c/div\u003e\n\n---\n\n## Features\n\n- Gorgeous auto optimized re-render\n- Automatic request loading\n- Extremely simple API\n\n## Install\n\n```sh\npnpm add flooks\n# or\nyarn add flooks\n# or\nnpm i flooks\n```\n\n## Usage\n\n```jsx\nimport create from 'flooks';\n\nconst useCounter = create((store) =\u003e ({\n  count: 0,\n  add() {\n    const { count } = store();\n    store({ count: count + 1 });\n  },\n  async addAsync() {\n    await new Promise((resolve) =\u003e setTimeout(resolve, 1000));\n    const { add } = store();\n    add();\n  },\n}));\n\nfunction Counter() {\n  const { count, add, addAsync } = useCounter();\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{count}\u003c/p\u003e\n      \u003cbutton onClick={add}\u003e+\u003c/button\u003e\n      \u003cbutton onClick={addAsync}\u003e+~ {addAsync.loading \u0026\u0026 '...'}\u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n**\\* Automatic request loading** - if a function is async, `asyncFn.loading` is its loading state. If `asyncFn.loading` is not used, no extra re-render.\n\n## Demo\n\n[![Edit flooks](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/flooks-gqye5?file=/src/Home.jsx)\n\n## Auto optimization\n\nflooks realizes a gorgeous auto optimization, only actually used data will be injected into the component, re-render completely on demand, when React is truly \"react\".\n\n### Why flooks over zustand?\n\n```js\n// zustand, need a selector\nconst { nuts, honey } = useStore((state) =\u003e ({\n  nuts: state.nuts,\n  honey: state.honey,\n}));\n\n// flooks, not need a selector\n// but also only `nuts` or `honey` update trigger re-render, it's automatic\nconst { nuts, honey } = useStore();\n```\n\n### Only functions, no re-render\n\n```js\nconst { a } = useStore(); // A component, update `a`\nconst { fn } = useStore(); // B component, only functions, no re-render\n```\n\n### No updated state, no re-render\n\n```js\nconst { a } = useStore(); // A component, update `a`\nconst { b } = useStore(); // B component, no `a`, no re-render\n```\n\n### No fn.loading, no extra re-render\n\n```js\nconst { asyncFn } = useStore(); // A component, call `asyncFn`\nasyncFn(); // No `asyncFn.loading`, no extra re-render\n\n// With normal loading solutions, even `asyncFn.loading` is not used,\n// it will re-render at least twice (turn `true` then `false`).\n```\n\n## API\n\n### `create()`\n\n```js\nimport create from 'flooks';\n\nconst useStore = create((store) =\u003e obj);\n\n// For `react\u003c=17`, you can use `create.config()` to pass\n// `ReactDOM.unstable_batchedUpdates` for batch updating in async updates.\n//\n// create.config({ batch: ReactDOM.unstable_batchedUpdates }); // at app entry\n```\n\n### `store()`\n\n```js\nimport create from 'flooks';\n\nconst useStore = create((store) =\u003e ({\n  fn() {\n    const { a, b } = store(); // get state\n\n    store({ a: a + b }); // update state by data\n    // or\n    store((state) =\u003e ({ a: state.a + state.b })); // update state by function\n  },\n}));\n```\n\n## License\n\n[MIT License](https://github.com/nanxiaobei/flooks/blob/main/LICENSE) (c) [nanxiaobei](https://lee.so/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanxiaobei%2Fflooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanxiaobei%2Fflooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanxiaobei%2Fflooks/lists"}