{"id":28819950,"url":"https://github.com/skimklin/umi-plugin-unstated","last_synced_at":"2025-07-14T09:08:30.667Z","repository":{"id":57385689,"uuid":"398464091","full_name":"skimklin/umi-plugin-unstated","owner":"skimklin","description":"umi plugin based on unstated-next","archived":false,"fork":false,"pushed_at":"2023-10-19T04:48:35.000Z","size":729,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-18T21:02:09.441Z","etag":null,"topics":["hooks","react","reactjs","umi","umi-plugin","umijs","unstated","unstated-next"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/umi-plugin-unstated","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/skimklin.png","metadata":{"files":{"readme":"README-zh_CN.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,"zenodo":null}},"created_at":"2021-08-21T04:20:34.000Z","updated_at":"2023-10-08T09:14:19.000Z","dependencies_parsed_at":"2025-06-18T21:02:12.983Z","dependency_job_id":"d140afcc-f1a1-49eb-bd97-fb4079f21868","html_url":"https://github.com/skimklin/umi-plugin-unstated","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skimklin/umi-plugin-unstated","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skimklin%2Fumi-plugin-unstated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skimklin%2Fumi-plugin-unstated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skimklin%2Fumi-plugin-unstated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skimklin%2Fumi-plugin-unstated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skimklin","download_url":"https://codeload.github.com/skimklin/umi-plugin-unstated/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skimklin%2Fumi-plugin-unstated/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265265829,"owners_count":23737112,"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","react","reactjs","umi","umi-plugin","umijs","unstated","unstated-next"],"created_at":"2025-06-18T21:01:56.367Z","updated_at":"2025-07-14T09:08:30.656Z","avatar_url":"https://github.com/skimklin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# umi-plugin-unstated\n\n\u003e umi-plugin-unstated\n\n基于unstated-next(https://github.com/jamiebuilds/unstated-next)的umi插件，自动读取文件注册container。\n2.x对应umi 4.x，[1.x](https://github.com/skimklin/umi-plugin-unstated/blob/version1.x/README.md)对应umi 3.x版本，根据需求选用不同版本。\n\n[English](README.md) | 简体中文\n\n## 安装\n\n使用 npm:\n\n```bash\n$ npm install umi-plugin-unstated\n```\n\n使用 yarn:\n\n```bash\n$ yarn add umi-plugin-unstated\n```\n\n使用 pnpm:\n\n```bash\n$ pnpm add umi-plugin-unstated\n```\n \n## 使用\n\n1. 在 umi 生成的 config 文件添加以下配置\n\n```javascript\n// in umi config file\nexport default defineConfig({\n  unstated: {\n    /**\n     * global: boolean | string[]\n     * 1. 若值为true，会把uModels下所有合法文件的默认导出全部注册到全局（不推荐）\n     * 2. 若值为sting[]，会把列表中存在的注册到全局，剩下的用户自行处理（性能较好）\n     * 3. uModels所有合法文件都会注册为Container并添加到umi下，导出key为uModels（import { uModels } from 'umi'）\n     */\n    global: ['global'],\n    /**\n     * 读取src下目录名\n     */\n    folder: 'uModels',\n    /**\n     * 调试模式，更多的输出信息\n     */\n    debug: true,\n  },\n});\n```\n\n2. src 下新建`uModels`文件夹，并添加文件`global.tsx`\n\n```javascript\nimport { useState } from 'react';\n\nexport default function useGlobal() {\n  const [global] = useState('global');\n\n  return {\n    global,\n  };\n}\n```\n\n3. 在页面中使用。如果 model 已经全局注册，可直接使用\n\n```javascript\nimport React from 'react';\nimport { uModels } from 'umi';\n\nconst App = () =\u003e {\n  const { global } = uModels.global.useContainer();\n  return \u003cdiv\u003e{global}\u003c/div\u003e;\n};\n```\n\n4. 在页面中使用。如果 model 未全局注册，使用如下\n\n```javascript\n// src/uModels/example.tsx\nimport { useState } from 'react'\n\nexport default function useExample() {\n  const [exampleState] = useState('example')\n\n  return {\n    exampleState,\n  }\n}\n\n// MyComponent.tsx\nimport React from 'react';\nimport { uModels } from 'umi';\n\nconst ChildComponent = () =\u003e {\n  const { exampleState } = uModels.example.useContainer();\n  return (\n    \u003cdiv\u003e\n      child: {exampleState}\n    \u003c/div\u003e\n  )\n}\nconst MyComponent = () =\u003e {\n  const { exampleState } = uModels.example.useContainer();\n  return (\n    \u003cdiv\u003e\n      {exampleState}\n      \u003cChildComponent/\u003e\n    \u003c/div\u003e\n  )\n}\n\nexport default () =\u003e uModels.example.wrapProvider(\u003cMyComponent/\u003e)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskimklin%2Fumi-plugin-unstated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskimklin%2Fumi-plugin-unstated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskimklin%2Fumi-plugin-unstated/lists"}