Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
skimklin committed Oct 19, 2023
1 parent 8a97610 commit 2664950
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 0 additions & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

## 安装


使用 npm:

```bash
Expand Down
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

> umi-plugin-unstated
基于unstated-next(https://github.com/jamiebuilds/unstated-next)的umi插件,自动读取文件注册container。
2.x对应umi 4.x,[1.x](https://github.com/skimklin/umi-plugin-unstated/blob/version1.x/README.md)对应umi 3.x版本,根据需求选用不同版本。
Based on unstated-next(https://github.com/jamiebuilds/unstated-next) umi plugin, automatically read the file to register the container.
2.x corresponds to umi 4.x, [1.x](https://github.com/skimklin/umi-plugin-unstated/blob/version1.x/README.md) corresponds to umi 3.x version, use different version according to your requirement.

English | [简体中文](README-zh_CN.md)

## Install

Expand All @@ -14,40 +16,46 @@ Using npm:
$ npm install umi-plugin-unstated
```

or using yarn:
Using yarn:

```bash
$ yarn add umi-plugin-unstated
```

Using pnpm:

```bash
$ pnpm add umi-plugin-unstated
```

## Usage

1. 在 umi 生成的 config 文件添加以下配置
1. Add the following configuration to the config file generated by umi

```javascript
// in umi config file
export default defineConfig({
unstated: {
/**
* global: boolean | string[]
* 1. 若值为true,会把uModels下所有合法文件的默认导出全部注册到全局(不推荐)
* 2. 若值为sting[],会把列表中存在的注册到全局,剩下的用户自行处理(性能较好)
* 3. uModels所有合法文件都会注册为Container并添加到umi下,导出key为uModels(import { uModels } from 'umi'
* 1. If the value is true, it will register all default exports of all legal files under uModels to the global (not recommended)
* 2. If the value is sting[], it will register the ones present in the list to the global, and the user will handle the rest (better performance)
* 3. All legal files of uModels are registered as Container and added under umi, exporting the key as uModels (import { uModels } from 'umi')
*/
global: ['global'],
/**
* 读取src下目录名
* Retrieve the name of the directory under src
*/
folder: 'uModels',
/**
* 调试模式,更多的输出信息
* Debug mode, more output information
*/
debug: true,
},
});
```

2. src 下新建`uModels`文件夹,并添加文件`global.tsx`
2. Create a new `uModels` folder under src and add the file `global.tsx`.

```javascript
import { useState } from 'react';
Expand All @@ -61,7 +69,7 @@ export default function useGlobal() {
}
```

3. 在页面中使用。如果 model 已经全局注册,可直接使用
3. Use it on the page. If the model is registered globally, you can use it directly as follows

```javascript
import React from 'react';
Expand All @@ -73,7 +81,7 @@ const App = () => {
};
```

1. 在页面中使用。如果 model 未全局注册,使用如下
4. In the page. If the model is not globally registered, use the following

```javascript
// src/uModels/example.tsx
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umi-plugin-unstated",
"version": "2.0.2",
"version": "2.0.3",
"description": "umi-plugin-unstated",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit 2664950

Please sign in to comment.